private void do_oauth2(OAuth2Params p) { Chilkat.OAuth2 oauth2 = new Chilkat.OAuth2(); oauth2.ListenPort = p.ListenPort; oauth2.AuthorizationEndpoint = p.AuthorizationEndpoint; oauth2.TokenEndpoint = p.TokenEndpoint; oauth2.ClientId = p.ClientId; oauth2.ClientSecret = p.ClientSecret; oauth2.CodeChallenge = true; oauth2.CodeChallengeMethod = "S256"; if ((p.Scope != null) && (p.Scope.Length > 0)) { oauth2.Scope = p.Scope; } // Begin the OAuth2 flow. Returns a URL that should be loaded in a browser. string url = oauth2.StartAuth(); if (url == null) { textBox1.Text = oauth2.LastErrorText; MessageBox.Show("StartAuth failed."); return; } m_oauth2 = oauth2; // Start a web browser and load the url. // This is where the end-user should accept or deny the authorization request. System.Diagnostics.Process.Start(url); // Monitor for the OAuth2 completion. m_oauth2.OnTaskCompleted += oauth2_OnTaskCompleted; Chilkat.Task task = m_oauth2.MonitorAsync(); if (task == null) { MessageBox.Show("Failed to start monitoring."); return; } // Start the task. // oauth2_OnTaskCompleted will be called when the end-user responds from the browser. task.Run(); // We're done with the .NET task object. // The underlying (internal) Chilkat task is running in a background thread. // Disposing of the .NET object does not affect the task that is running. // It is important to dispose of .NET's reference to the underlying object so that // when the task does complete, it is deallocated. Otherwise, a reference // to the underlying task remains and would only get removed when .NET // garbage collects. task.Dispose(); task = null; return; }
private void btnMsGraph_Click(object sender, EventArgs e) { clearTextBoxes(); disposeOldOAuth2(); OAuth2Params p = new OAuth2Params(); p.ListenPort = Convert.ToInt32(txtListenPort.Text); p.AuthorizationEndpoint = msGraphAuthEndpoint; p.TokenEndpoint = msGraphTokenEndpoint; p.ClientId = msGraphClientId; p.ClientSecret = msGraphClientSecret; p.Scope = "openid profile offline_access user.readwrite mail.readwrite mail.send files.readwrite"; do_oauth2(p); }
private void btnGitHub_Click(object sender, EventArgs e) { clearTextBoxes(); disposeOldOAuth2(); OAuth2Params p = new OAuth2Params(); p.ListenPort = Convert.ToInt32(txtListenPort.Text); p.AuthorizationEndpoint = gitAuthEndpoint; p.TokenEndpoint = gitTokenEndpoint; p.ClientId = gitClientId; p.ClientSecret = gitClientSecret; do_oauth2(p); return; }
private void btnLinkedIn_Click(object sender, EventArgs e) { clearTextBoxes(); disposeOldOAuth2(); OAuth2Params p = new OAuth2Params(); // This should match the Authorized Redirect URL in your LinkedIn app, which would look like "http://localhost:3017/" p.ListenPort = Convert.ToInt32(txtListenPort.Text); p.AuthorizationEndpoint = linkedinAuthEndpoint; p.TokenEndpoint = linkedinTokenEndpoint; p.ClientId = linkedinClientId; p.ClientSecret = linkedinClientSecret; do_oauth2(p); return; }
private void btnGoogle_Click(object sender, EventArgs e) { clearTextBoxes(); disposeOldOAuth2(); OAuth2Params p = new OAuth2Params(); p.ListenPort = 0; p.AuthorizationEndpoint = googleAuthorizationEndpoint; p.TokenEndpoint = googleTokenEndpoint; p.ClientId = googleAppClientId; p.ClientSecret = googleAppClientSecret; // This is the scope for Google Drive. // See https://developers.google.com/identity/protocols/googlescopes p.Scope = "https://www.googleapis.com/auth/drive"; do_oauth2(p); return; }
private void btnFacebook_Click(object sender, EventArgs e) { clearTextBoxes(); disposeOldOAuth2(); OAuth2Params p = new OAuth2Params(); // This matches the Site URL configured for our Facebook APP, which is "http://localhost:3017/" p.ListenPort = Convert.ToInt32(txtListenPort.Text); p.AuthorizationEndpoint = facebookAuthEndpoint; p.TokenEndpoint = facebookTokenEndpoint; p.ClientId = facebookClientId; p.ClientSecret = facebookClientSecret; // Set the Scope to a comma-separated list of permissions the app wishes to request. // See https://developers.facebook.com/docs/facebook-login/permissions/ for a full list of permissions. p.Scope = "public_profile,user_friends,email,user_posts,user_likes,user_photos"; do_oauth2(p); return; }