/// <summary> /// Method to get the authorization from the user to access their Google Drive from the application /// </summary> /// <param name="client"></param> /// <returns></returns> public static IAuthorizationState GetAuthorization(NativeApplicationClient client) { // You should use a more secure way of storing the key here as // .NET applications can be disassembled using a reflection tool. const string STORAGE = "gdrive_uploader"; const string KEY = "z},drdzf11x9;87"; string scope = DriveService.Scopes.Drive.GetStringValue(); // Check if there is a cached refresh token available. IAuthorizationState state = AuthorizationMgr.GetCachedRefreshToken(STORAGE, KEY); if (state != null) { try { client.RefreshToken(state); return(state); // Yes - we are done. } catch (DotNetOpenAuth.Messaging.ProtocolException ex) { Debug.WriteLine("Using existing refresh token failed: " + ex.Message); } } // If we get here, there is no stored token. Retrieve the authorization from the user. state = AuthorizationMgr.RequestNativeAuthorization(client, scope); AuthorizationMgr.SetCachedRefreshToken(STORAGE, KEY, state); return(state); }
private static IAuthorizationState GetAuthentication(NativeApplicationClient client) { // You should use a more secure way of storing the key here as // .NET applications can be disassembled using a reflection tool. const string STORAGE = "google.samples.dotnet.prediction"; const string KEY = "AF41sdBra7ufra)VD:@#A#a++=3e"; string scope = PredictionService.Scopes.Prediction.GetStringValue(); // Check if there is a cached refresh token available. IAuthorizationState state = AuthorizationMgr.GetCachedRefreshToken(STORAGE, KEY); if (state != null) { try { client.RefreshToken(state); return(state); // Yes - we are done. } catch (DotNetOpenAuth.Messaging.ProtocolException ex) { CommandLine.WriteError("Using existing refresh token failed: " + ex.Message); } } // Retrieve the authorization from the user. state = AuthorizationMgr.RequestNativeAuthorization(client, scope); AuthorizationMgr.SetCachedRefreshToken(STORAGE, KEY, state); return(state); }
public static IAuthorizationState GetAuthorization(NativeApplicationClient Client) { try { const string KEY = "z},drdzf11x9;87"; string myScope = DriveService.Scopes.Drive.GetStringValue(); // Check if there is a cached refresh token available. IAuthorizationState myState = AuthorizationMgr.GetCachedRefreshToken(KEY); if (myState != null) { try { Client.RefreshToken(myState); return(myState); // Yes - we are done. } catch (DotNetOpenAuth.Messaging.ProtocolException ex) { ErrorDump.AddError(System.IntPtr.Zero, "GAuth.cs", "GetAuthorization", ex, "Using existing refresh token failed"); } } // If we get here, there is no stored token. Retrieve the authorization from the user. myState = AuthorizationMgr.RequestNativeAuthorization(Client, myScope); AuthorizationMgr.SetCachedRefreshToken(KEY, myState); return(myState); } catch (Exception ex) { ErrorDump.AddError(System.IntPtr.Zero, "GAuth.cs", "GetAuthorization", ex); return(null); } }
private IAuthorizationState getAuthorisation(NativeApplicationClient client) { IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() }); state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); string refreshToken = LoadRefreshToken(); if (!String.IsNullOrWhiteSpace(refreshToken)) { state.RefreshToken = refreshToken; if (client.RefreshToken(state)) { return(state); } } if (!authRefreshOnly && authFunction != null) { Uri authUri = client.RequestUserAuthorization(state); string authResult = authFunction(authUri); var result = client.ProcessUserAuthorization(authResult, state); StoreRefreshToken(state); return(result); } else { return(null); } }
private static IAuthorizationState GetAuthorization(NativeApplicationClient client) { // You should use a more secure way of storing the key here as // .NET applications can be disassembled using a reflection tool. const string STORAGE = "google.samples.dotnet.urlshortener"; const string KEY = "S7Uf8AsapUWrac798uga5U8e5azePhAf"; // Check if there is a cached refresh token available. IAuthorizationState state = AuthorizationMgr.GetCachedRefreshToken(STORAGE, KEY); if (state != null) { try { client.RefreshToken(state); return(state); // Yes - we are done. } catch (DotNetOpenAuth.Messaging.ProtocolException ex) { CommandLine.WriteError("Using existing refresh token failed: " + ex.Message); } } // Retrieve the authorization from the user. state = AuthorizationMgr.RequestNativeAuthorization(client, Scope); AuthorizationMgr.SetCachedRefreshToken(STORAGE, KEY, state); return(state); }
private static IAuthorizationState GetAuthentication(NativeApplicationClient client) { // You should use a more secure way of storing the key here as // .NET applications can be disassembled using a reflection tool. const string STORAGE = cacheFile; const string KEY = "y},drdzf11x9;87"; string scope = Google.Apis.Plus.v1.PlusService.Scopes.PlusMe.GetStringValue(); // Check if there is a cached refresh token available. IAuthorizationState state = AuthorizationMgr.GetCachedRefreshToken(STORAGE, KEY); if (state != null) { try { client.RefreshToken(state); return(state); // Yes - we are done. } catch (DotNetOpenAuth.Messaging.ProtocolException ex) { ex.ShowError(); } } // Retrieve the authorization from the user. state = AuthorizationMgr.RequestNativeAuthorization(client, scope); AuthorizationMgr.SetCachedRefreshToken(STORAGE, KEY, state); return(state); }
private IAuthorizationState getState(NativeApplicationClient arg) { IAuthorizationState state = new AuthorizationState(new[] { scope }); state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); state.RefreshToken = refreshToken; arg.RefreshToken(state); return(state); }
internal static IAuthorizationState GetState(NativeApplicationClient arg) { IAuthorizationState state = new AuthorizationState(SCOPES); state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); state.RefreshToken = SavedRefreshToken; arg.RefreshToken(state); return(state); }
public static IAuthorizationState GetAuthorization(NativeApplicationClient arg) { IAuthorizationState state = new AuthorizationState( new[] { CalendarService.Scopes.Calendar.GetStringValue() } ); state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); string refreshToken = LoadRefreshToken(); if (!String.IsNullOrWhiteSpace(refreshToken)) { state.RefreshToken = refreshToken; if (arg.RefreshToken(state)) { return(state); } } Uri authUri = arg.RequestUserAuthorization(state); Process.Start(authUri.ToString()); string authCode = ""; AuthenticationForm authenticationDialog = new AuthenticationForm(); authenticationDialog.ShowDialog(); if (authenticationDialog.DialogResult.HasValue && authenticationDialog.DialogResult.Value) { authCode = authenticationDialog.authToken.Text; if (authCode == String.Empty) { Application.Current.Shutdown(); } } authenticationDialog.Hide(); var result = arg.ProcessUserAuthorization(authCode, state); StoreRefreshToken(state); return(result); }
private IAuthorizationState getState(NativeApplicationClient arg) { IAuthorizationState state = new AuthorizationState(new[] { scope }); state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); state.RefreshToken = refreshToken; arg.RefreshToken(state); YouTubeRequestSettings settings = new YouTubeRequestSettings(Strings.YouTube_ProductName, Strings.YouTube_DeveloperKey, state.AccessToken); request = new YouTubeRequest(settings); return(state); }
public static GoogleAuthenticator RefreshAuthenticator(string refreshToken) { var state = new AuthorizationState(_scopes) { RefreshToken = refreshToken }; var client = new NativeApplicationClient(GoogleAuthenticationServer.Description, _clientId, _clientSecret); bool result = client.RefreshToken(state); var auth = new OAuth2Authenticator <NativeApplicationClient>(client, (c) => state); auth.LoadAccessToken(); return(new GoogleAuthenticator(auth)); }
private static IAuthorizationState GetAuthorization(NativeApplicationClient client) { var storage = MethodBase.GetCurrentMethod().DeclaringType.ToString(); var key = "storage_key"; IAuthorizationState state = AuthorizationMgr.GetCachedRefreshToken(storage, key); if (state != null) { client.RefreshToken(state); } else { state = AuthorizationMgr.RequestNativeAuthorization(client, YoutubeService.Scopes.YoutubeUpload.GetStringValue()); AuthorizationMgr.SetCachedRefreshToken(storage, key, state); } return(state); }
IAuthorizationState GetAuthorization(NativeApplicationClient arg) { IAuthorizationState state = new AuthorizationState(new[] { BigqueryService.Scopes.Bigquery.GetStringValue() }) { Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl) }; string authToken = GetRefreshToken(); if (!string.IsNullOrEmpty(authToken)) { state.RefreshToken = authToken; if (arg.RefreshToken(state)) { return state; } } authToken = GetAuthorizationCodeFromUser(arg, state); arg.ProcessUserAuthorization(authToken, state); SaveNewRefreshToken(state); return state; }
private static IAuthorizationState GetAuthentication(NativeApplicationClient arg) { // Get the auth URL: IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() }); state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl); state.RefreshToken = Settings.Instance.RefreshToken; Uri authUri = arg.RequestUserAuthorization(state); IAuthorizationState result = null; if (state.RefreshToken == "") { // Request authorization from the user (by opening a browser window): Process.Start(authUri.ToString()); EnterAuthorizationCode eac = new EnterAuthorizationCode(); if (eac.ShowDialog() == DialogResult.OK) { // Retrieve the access/refresh tokens by using the authorization code: result = arg.ProcessUserAuthorization(eac.authcode, state); //save the refresh token for future use Settings.Instance.RefreshToken = result.RefreshToken; XMLManager.Export(Settings.Instance, MainForm.FILENAME); return(result); } else { return(null); } } else { arg.RefreshToken(state, null); result = state; return(result); } }