Пример #1
0
        public async Task <BearerAccessToken> GetUserAccessToken(string userHash)
        {
            // get the refresh token for this user
            string refreshToken = await _refreshTokenProvider.GetRefreshToken(userHash);

            if (string.IsNullOrEmpty(refreshToken))
            {
                throw new UnauthorizedAccessException($"No refresh token found for user \"{userHash}\"");
            }

            return(await GetAccessToken(userHash,
                                        $"grant_type=refresh_token&refresh_token={refreshToken}&redirect_uri={_config["SpotifyAuthRedirectUri"]}"));
        }
Пример #2
0
        public async Task <LogInResponse> LogInAsync(string userRole)
        {
            var refreshToken = _refreshTokenProvider.GetRefreshToken(DateTime.Now.AddMinutes(_config.RefreshTokenExpHours));

            _claims.Add("role", userRole);

            var accessToken = _accessTokenProvider.GetAccessToken(DateTime.Now.AddMinutes(_config.AccessTokenExpMinutes), _claims);

            //TODO Apply CQRS
            _tokensRepository.AddTokenAsync(await refreshToken, userRole);

            return(new LogInResponse()
            {
                AccessToken = accessToken,
                RefreshToken = await refreshToken
            });
        }