Example #1
0
        public async Task <ActionResult> Authorize(CancellationToken cancellationToken)
        {
            var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).
                         AuthorizeAsync(cancellationToken);

            if (result.Credential != null)
            {
                GoogleAuthorization ga = new GoogleAuthorization()
                {
                    AccessToken  = result.Credential.Token.AccessToken,
                    ExpiresIn    = result.Credential.Token.ExpiresInSeconds.GetValueOrDefault(),
                    RefreshToken = result.Credential.Token.RefreshToken,
                    TokenType    = result.Credential.Token.TokenType
                };

                return(AuthorizedAction(ga));

                //var service = new DriveService(new BaseClientService.Initializer
                //{
                //    HttpClientInitializer = result.Credential,
                //    ApplicationName = "ASP.NET MVC Sample"
                //});

                //// YOUR CODE SHOULD BE HERE..
                //// SAMPLE CODE:
                //var list = await service.Files.List().ExecuteAsync();
                //ViewBag.Message = "FILE COUNT IS: " + list.Items.Count();
                //return View();
            }
            else
            {
                return(Redirect(result.RedirectUri));
            }
        }
Example #2
0
 public GoogleClient(GoogleAuthorization authorization)
 {
     Authorization          = authorization;
     httpClient             = new HttpClient();
     httpClient.BaseAddress = new Uri("https://www.googleapis.com");
     httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Authorization.AccessToken);
 }
Example #3
0
        internal static BaseClientService.Initializer GetInitializer(this GoogleAuthorization auth, string appName, Controller controller)
        {
            var result = new BaseClientService.Initializer()
            {
                HttpClientInitializer = auth.GetCredential(controller),
                ApplicationName       = "ASP.NET MVC Sample"
            };

            return(result);
        }
Example #4
0
        internal static UserCredential GetCredential(this GoogleAuthorization auth, Controller controller)
        {
            var meta   = new AppFlowMetadata();
            var app    = new AuthorizationCodeMvcApp(controller, meta);
            var result = new UserCredential(app.Flow, meta.GetUserId(controller), new TokenResponse()
            {
                AccessToken      = auth.AccessToken,
                ExpiresInSeconds = auth.ExpiresIn,
                RefreshToken     = auth.RefreshToken,
                TokenType        = auth.TokenType
            });

            return(result);
        }
Example #5
0
 public DriveClient(GoogleAuthorization auth, Controller controller)
 {
     _auth      = auth;
     Controller = controller;
 }
Example #6
0
 protected abstract ActionResult AuthorizedAction(GoogleAuthorization auth);