Esempio n. 1
0
 public static ClientSecrets ToClientSecrets(GoogleSecrets secrets)
 {
     return(new ClientSecrets {
         ClientId = secrets.ClientId,
         ClientSecret = secrets.ClientSecret,
     });
 }
Esempio n. 2
0
        public bool Refresh()
        {
            TokenResponse token = new TokenResponse {
                AccessToken  = AccessToken,
                RefreshToken = RefreshToken
            };

            IAuthorizationCodeFlow flow =
                new AuthorizationCodeFlow(new AuthorizationCodeFlow.Initializer(GoogleAuthConsts.AuthorizationUrl, GoogleAuthConsts.TokenUrl)
            {
                ClientSecrets = GoogleSecrets.ToClientSecrets(Broker.Secrets),
                Scopes        = new [] { PlusService.Scope.PlusLogin }
            });

            UserCredential credential = new UserCredential(flow, "me", token);
            bool           success;

            try {
                success = credential.RefreshTokenAsync(CancellationToken.None).Result;
            } catch (AggregateException ex) {
                Log.Error("RefreshTokenAsync failed: ");
                Log.Indent++;
                Log.Error(ex);
                Log.Indent--;
                success = false;
            }

            if (success)
            {
                token       = credential.Token;
                AccessToken = token.AccessToken;
                Log.Debug("Refresh successful: ", AccessToken);
                return(true);
            }
            else
            {
                Log.Error("Refresh failed: ", this);
                return(false);
            }
        }