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);
        }
        public async Task Post(AddSyncTarget request)
        {
            var accessToken = await GetAccessToken(request.Code);

            var syncAccount = new OneDriveSyncAccount
            {
                Id   = Guid.NewGuid().ToString(),
                Name = WebUtility.UrlDecode(request.Name),
                EnableForEveryone = request.EnableForEveryone,
                UserIds           = request.UserIds,
                AccessToken       = accessToken
            };

            if (!string.IsNullOrEmpty(request.Id))
            {
                syncAccount.Id = request.Id;
            }

            _configurationRetriever.AddSyncAccount(syncAccount);
        }
Beispiel #3
0
        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);
        }