示例#1
0
 private async void RefreshTokenDelegatingHandler_TokenRefreshed(object sender, TokenRefreshedEventArgs e)
 => await _accountStorageService.SetAccountAsync(new Account()
 {
     AccessToken  = e.AccessToken,
     RefreshToken = e.RefreshToken,
     Expiration   = DateTime.Now.AddSeconds(e.ExpiresIn),
 });
示例#2
0
        /// <summary>
        /// Refreshes and stores the new token in account storage.
        /// Returns account you can use to access api.
        /// </summary>
        /// <returns>Account.</returns>
        public async Task <Account> RefreshTokenAsync()
        {
            var account = await _accountStorageService.GetAccountAsync();

            if (account != null)
            {
                var refreshTokenResult = await _oidcClient.RefreshTokenAsync(account.RefreshToken);

                if (!refreshTokenResult.IsError)
                {
                    var newAccount = new Account
                    {
                        AccessToken  = refreshTokenResult.AccessToken,
                        RefreshToken = refreshTokenResult.RefreshToken,
                        Expiration   = refreshTokenResult.AccessTokenExpiration
                    };
                    await _accountStorageService.SetAccountAsync(newAccount);

                    return(newAccount);
                }
            }
            return(null);
        }