Created
October 19, 2015 07:46
-
-
Save LindaLawton/efe03243052826c3b631 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void auth() | |
{ | |
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(GetTitle); | |
webBrowser1.Navigate(SimpleAuth.GetAuthURI().ToString()); | |
} | |
/// <summary> | |
/// Approval code comes in the title but sometimes not all of it so getting the Authentication code from the document text. | |
/// </summary> | |
/// <param name="sender"></param> | |
/// <param name="e"></param> | |
private void GetTitle(object sender, WebBrowserDocumentCompletedEventArgs e) | |
{ | |
string Mytitle = ((WebBrowser)sender).DocumentTitle.ToLower(); | |
if (Mytitle.IndexOf("success code=") > -1) | |
{ | |
webBrowser1.Visible = false; | |
// Title doesn't come back full all the time | |
string AuthCode = webBrowser1.DocumentTitle.Replace("Success code=", ""); | |
//riping it from the internal text | |
string blah = ((WebBrowser)sender).DocumentText; | |
int start = blah.IndexOf("id=\"code\""); | |
start = blah.IndexOf(AuthCode, start); | |
int end = blah.IndexOf('"', start); | |
AuthCode = blah.Substring(start, end - start); | |
GetAuth(AuthCode); | |
} | |
else if (Mytitle.IndexOf("denied error=") > -1) | |
{ | |
MessageBox.Show("You must be authentcated."); | |
auth(); | |
} | |
else | |
{ | |
// auth(); | |
} | |
} | |
/// <summary> | |
/// Used for getting authorization after the user has clicked on the web-browser control. | |
/// </summary> | |
/// <param name="AuthCode"></param> | |
public void GetAuth(string AuthCode) | |
{ | |
RefreshToken = string.Empty; | |
Cursor.Current = Cursors.WaitCursor; | |
RefreshToken = SimpleAuth.exchangeCode(AuthCode); | |
Cursor.Current = Cursors.Arrow; | |
this.DialogResult = DialogResult.OK; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment