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)); } }
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); }
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); }
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); }
public DriveClient(GoogleAuthorization auth, Controller controller) { _auth = auth; Controller = controller; }
protected abstract ActionResult AuthorizedAction(GoogleAuthorization auth);