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.siteverification"; const string KEY = "y},drdzf11x9;87"; // 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 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); }
private static IAuthorizationState GetAuthentication(NativeApplicationClient client) { // Retrieve the authorization from the user. return(AuthorizationMgr.RequestNativeAuthorization(client, Scope)); }