I ended up extracting the access code using a browser control that reads the value of the document title when the user selects the google account and grants access.
eg:
Generate url
RedirectURI = "urn:ietf:wg:oauth:2.0:oob" OAuth2Parameters parameters = new OAuth2Parameters() { ClientId = clientId, ClientSecret = clientSecret, RedirectUri = redirectUri, Scope = requiredScope }; // Request authorization from the user (by opening a browser window): string url = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); var loginUri = new Uri(url); // This form has browser control GoogleLoginForm form = new GoogleLoginForm(loginUri, redirectUri); var dr = form.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { parameters.AccessCode = form.OAuthVerifierToken; }
Then in GoogleLoginForm: We have browser control and the registered browserControl_Navigated event, and do the following. The DocumentTitle contains an access code that is used to generate a token.
private void GoogleLoginForm_Load(object sender, EventArgs e) { wbGoogleLogin.Url = _loginUri; } private void wbGoogleLogin_Navigated(object sender, WebBrowserNavigatedEventArgs e) { string fullPath = e.Url.ToString(); WebBrowser control = sender as WebBrowser; if (control != null && !string.IsNullOrEmpty(control.DocumentTitle) && control.DocumentTitle.Contains("Success code")) { _OAuthVerifierToken = control.DocumentTitle.Replace("Success code=",""); DialogResult = DialogResult.OK; } }
Thus, this can be done in the same piece of code, without having to write a complex callback service to read the access token back into our system.
Itβs not entirely clear why this is built into the api calendar, but the contacts API is not.
source share