Retrieve PIN from Textbox

Mar 22, 2013 at 12:21 AM
Hi, In my application when a user begins the inital authentication process for PIN verification they are directed to a page with a WebBrowser, Cancel button, Textbox, and Authenticate button.

What I am trying to achieve is for the user to authorize the app in the webbrowser where they will then be shown the PIN. They will then enter the PIN into the Textbox, and when they click Authenticate then the Authorize() part of the PinAuthorizer will be done.

The trouble is that if I put the Authorize instruction in another procedure such as the click event for the Authorize button, the WebBrowser will not be instructed to navigate to the Auth page for some reason.

If I use the code in my first example it takes the code from the Pin box immediately, which is empty because the user does not have a chance to enter the code in the box before it goes on to authorize, let alone click on the authenticate button to initiate the authorization.

Note Auth is globally declared.
Credentials = New InMemoryCredentials
            Credentials.ConsumerKey = My.Settings.ConsumerKey
            Credentials.ConsumerSecret = My.Settings.ConsumerSecret
            TabControl1.SelectedItem = TabAuthBrowser
            Auth.UseCompression = True
            Auth.Credentials = Credentials
            Auth.GoToTwitterAuthorization = Sub(pagelink) WebBrowserAuth.Navigate(pagelink)
End Sub

   Private Function PinCallback() As String
        Dim Authcode As String
        Authcode = TxtAuthCode.Text
        Return Authcode
    End Function
Ideally what I'd Like to do is below.
Private Sub BtnSignIn_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BtnSignIn.Click
        Try
            Credentials = New InMemoryCredentials
            Credentials.ConsumerKey = My.Settings.ConsumerKey
            Credentials.ConsumerSecret = My.Settings.ConsumerSecret
            TabControl1.SelectedItem = TabAuthBrowser
            Auth.UseCompression = True
            Auth.Credentials = Credentials
            Auth.GoToTwitterAuthorization = Sub(pagelink) WebBrowserAuth.Navigate(pagelink)
            Auth.GetPin = AddressOf PinCallback
        Catch Ex As Exception
            MessageBox.Show("An error has occured - " & Ex.Message, "Sign In Error", MessageBoxButton.OK)
            AppProcedure.Auth.SignOut(TabControl1, FmeStat, FmeAvatar, LblTwitterName, BtnSignOut, TabSignIn, InstDir)
        End Try
End Sub

'''Then progress onto the below procedure.


Private Sub BtnAuthenticate_Click(sender As Object, e As RoutedEventArgs) Handles BtnAuthenticate.Click
        Try
            Auth.GetPin = AddressOf PinCallback
            Auth.Authorize()
            twitterCtx = New TwitterContext(Auth)
            '''Other stuff here
        Catch Ex As Exception
            MessageBox.Show("An error has occured - " & Ex.Message, "Sign In Error", MessageBoxButton.OK)
            AppProcedure.Auth.SignOut(TabControl1, FmeStat, FmeAvatar, LblTwitterName, BtnSignOut, TabSignIn, InstDir)
        End Try
    End Sub
Coordinator
Mar 22, 2013 at 4:27 PM
Hi,

There are working demos on the samples page that you might want to step through to see how the flow works: http://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20Samples&referringTitle=Home

@JoeMayo