public async Task <bool> TryRefreshSessionAsync(SessionInfo session)
        {
            return(await Task.Run(async() =>
            {
                var sessionInfo = session;

                var refreshToken = sessionInfo?.RefreshToken;

                if (refreshToken != null)
                {
                    try
                    {
                        var tokenRefreshResult = await _tokenRefreshInvoker.InvokeRefreshTokenAsync(refreshToken).ConfigureAwait(false);

                        await _sessionInfoContainer.AddOrReplaceAsync(tokenRefreshResult).ConfigureAwait(false);

                        return true;
                    }
                    catch (Exception ex)
                    {
                        _logger.LogWarning(ex, "Cannot refresh the token");
                    }
                }

                return false;
            }).ConfigureAwait(false));
        }
Esempio n. 2
0
        public async Task InitUserInfoAsync(Metadata metadata, UserState profile, Token token)
        {
            // metadata should be set first
            await _metadataContainer.SetAsync(metadata).ConfigureAwait(false);

            await _userProfileContainer.SetAsync(profile).ConfigureAwait(false);

            var accountInformation = profile == null ? null : new Models.AccountInformation(profile.Roles);
            await _accountContainer.SetAsync(accountInformation).ConfigureAwait(false);

            await _sessionContainer.AddOrReplaceAsync(SessionInfo.CreateFromToken(token)).ConfigureAwait(false);
        }