Exemple #1
0
 public static DriveService GetServiceForWebApplication(AuthorizationCodeWebApp.AuthResult authorization)
 {
     if (authorization.Credential != null)
     {
         return(new DriveService(new BaseClientService.Initializer
         {
             HttpClientInitializer = authorization.Credential,
             ApplicationName = _ApplicationName
         }));
     }
     return(null);
 }
        public async Task <MetricDataImport> GetData(int companyId, ExternalApiAuth externalApiAuth, AuthorizationCodeWebApp.AuthResult authResult, IEnumerable <MetricDataPoint> metricDataPoints)
        {
            var metricDataImport = new MetricDataImport {
                success = true
            };

            if (externalApiAuth == null)
            {
                // user is not connected to this API
                return(metricDataImport);
            }

            if (authResult.Credential == null)
            {
                // should be connected, but Google says we're not
                metricDataImport.errors.Add(new JsonError {
                    ErrorMessage = "Google Analytics authorization revoked - unable to get data"
                });

                return(metricDataImport);
            }

            metricDataImport.results = GAReports(externalApiAuth, authResult, metricDataPoints);

            return(metricDataImport);
        }
Exemple #3
0
    public static AuthorizationCodeWebApp.AuthResult checkExpiration(Controller controller, AuthorizationCodeWebApp.AuthResult authorization)
    {
        if (authorization.Credential.Token.IsExpired(Google.Apis.Util.SystemClock.Default))
        {
            Google.Apis.Auth.OAuth2.Responses.TokenResponse token = new Google.Apis.Auth.OAuth2.Responses.TokenResponse();
            //recreate the token
            token = authorization.Credential.Flow.RefreshTokenAsync(
                UserAccountsController.getUserId(controller.Session).ToString(),
                authorization.Credential.Token.RefreshToken,
                CancellationToken.None
                ).Result;

            authorization = getAuthorization(controller);
        }
        return(authorization);
    }