Skip to content

Instantly share code, notes, and snippets.

@vadimii
Created September 5, 2012 06:05
Show Gist options
  • Save vadimii/3631357 to your computer and use it in GitHub Desktop.
Save vadimii/3631357 to your computer and use it in GitHub Desktop.
Recieve Google Auth Refresh Token
var CLIENT_ID = "<YOUR CLIENT ID>";
var CLIENT_SECRET = "<YOUR CLIENT SECRET>";
var provider = new NativeApplicationClient(
GoogleAuthenticationServer.Description,
CLIENT_ID,
CLIENT_SECRET);
IAuthorizationState state = new AuthorizationState(new[] {
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/userinfo.email"
});
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
var authUri = provider.RequestUserAuthorization(state);
var authUriString = authUri.ToString();
Clipboard.SetText(authUriString);
Console.Write(
"Go to: {1}{1}{0}{1}{1}Then recieve and paste{1}",
authUriString,
Environment.NewLine);
Console.Write("Authorization Code: ");
var authCode = Console.ReadLine();
state = provider.ProcessUserAuthorization(authCode, state);
Clipboard.SetText(state.RefreshToken);
Console.Write("Your refresh token is: {0}", state.RefreshToken);
using System;
using System.Windows.Forms;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment