private async Task <string> GetAccessToken(string code) { var config = _configurationRetriever.GetGeneralConfiguration(); var token = await _dropboxApi.AcquireToken(code, config.DropboxAppKey, config.DropboxAppSecret, CancellationToken.None); return(token.access_token); }
private GoogleCredentials GetGoogleCredentials(SyncTarget target) { var syncAccount = _configurationRetriever.GetSyncAccount(target.Id); var generalConfig = _configurationRetriever.GetGeneralConfiguration(); return(new GoogleCredentials { RefreshToken = syncAccount.RefreshToken, ClientId = generalConfig.GoogleDriveClientId, ClientSecret = generalConfig.GoogleDriveClientSecret }); }
public async Task Post(AddSyncTarget request) { var config = _configurationRetriever.GetGeneralConfiguration(); var refreshToken = await GetRefreshToken(request); var syncAccount = new GoogleDriveSyncAccount { Id = Guid.NewGuid().ToString(), Name = WebUtility.UrlDecode(request.Name), EnableForEveryone = request.EnableForEveryone, UserIds = request.UserIds, RefreshToken = refreshToken, FolderId = await GetOrCreateFolder(config.GoogleDriveClientId, config.GoogleDriveClientSecret, refreshToken) }; if (!string.IsNullOrEmpty(request.Id)) { syncAccount.Id = request.Id; } _configurationRetriever.AddSyncAccount(syncAccount); }
private async Task <Token> GetAccessToken(string code) { var config = _configurationRetriever.GetGeneralConfiguration(); var now = DateTime.Now; var token = await _liveAuthenticationApi.AcquireToken(code, Constants.OneDriveRedirectUrl, config.OneDriveClientId, config.OneDriveClientSecret, CancellationToken.None); return(new Token { AccessToken = token.access_token, ExpiresAt = now.AddSeconds(token.expires_in), RefresToken = token.refresh_token }); }
private async Task RefreshToken(CancellationToken cancellationToken) { var config = _configurationRetriever.GetGeneralConfiguration(); var now = DateTime.UtcNow; var refreshToken = await _liveAuthenticationApi.RefreshToken(_accessToken.RefresToken, Constants.OneDriveRedirectUrl, config.OneDriveClientId, config.OneDriveClientSecret, cancellationToken); _accessToken.AccessToken = refreshToken.access_token; _accessToken.ExpiresAt = now.AddSeconds(refreshToken.expires_in); _accessToken.RefresToken = refreshToken.refresh_token; var syncAccount = _configurationRetriever.GetSyncAccount(_syncAccountId); syncAccount.AccessToken = _accessToken; _configurationRetriever.AddSyncAccount(syncAccount); }
private GoogleCredentials GetGoogleCredentials(SyncTarget target) { var syncAccount = _configurationRetriever.GetSyncAccount(target.Id); var generalConfig = _configurationRetriever.GetGeneralConfiguration(); if (syncAccount == null) { _logger.Error("Could not locate a sync target for {0} ({1})", target.Name, target.Id); throw new Exception("no sync account"); } return(new GoogleCredentials { RefreshToken = syncAccount.RefreshToken, ClientId = generalConfig.GoogleDriveClientId, ClientSecret = generalConfig.GoogleDriveClientSecret }); }