コード例 #1
0
        private string GetResultMessage(JwtAuthenticationResult <User> result)
        {
            switch (result.Type)
            {
            case AuthenticationResultType.InvalidUserNameOrEmailAddress:
                return("Usuário inválido");

            case AuthenticationResultType.InvalidPassword:
                return("Usuário ou senha inválidos");

            case AuthenticationResultType.UserIsNotActive:
                return("Usuário inativo");

            case AuthenticationResultType.InvalidTenancyName:
                return("Inquilino inválido");

            case AuthenticationResultType.TenantIsNotActive:
                return("Inquilino inativo");

            case AuthenticationResultType.UserEmailIsNotConfirmed:
                return("E-mail não confirmado");

            case AuthenticationResultType.UnauthenticatedUser:
                return("Usuário não autenticado");

            default:
                return("Não autorizado");
            }
        }
コード例 #2
0
        public Task <HttpContent> CreateRefreshRequestContentAsync()
        {
            // todo fixme
            var authenticationResult = new JwtAuthenticationResult();

            authenticationResult.RefreshToken = _refreshToken;
            authenticationResult.AccessToken  = _accessToken;
            return(Task.FromResult <HttpContent>(new StringContent(JsonSerializer.Serialize(authenticationResult), Encoding.UTF8, MediaTypeNames.Application.Json)));
        }
コード例 #3
0
        public async Task <HttpContent> CreateRefreshRequestContentAsync()
        {
            var authenticationResult = new JwtAuthenticationResult();

            authenticationResult.AccessToken = await _authenticationStorage.GetAccessTokenAsync();

            authenticationResult.RefreshToken = await _authenticationStorage.GetRefreshTokenAsync();

            return(new StringContent(JsonConvert.SerializeObject(authenticationResult), Encoding.UTF8, MediaTypeNames.Application.Json));
        }
コード例 #4
0
 public async Task UpdateTokenStoreAsync(JwtAuthenticationResult authenticationResult)
 {
     if (authenticationResult == null || authenticationResult.AuthenticationRequired)
     {
         _authenticationStorage.Clear();
     }
     else
     {
         await _authenticationStorage.UpdateAsync(authenticationResult.AccessToken, authenticationResult.RefreshToken);
     }
 }
コード例 #5
0
ファイル: JwtController.cs プロジェクト: taori/PCRemote2
        public async Task <ActionResult <JwtAuthenticationResult> > RefreshToken([FromBody] JwtAuthenticationResult model)
        {
            _logger.LogDebug("Refreshing token for RefreshToken {Token}", model.RefreshToken);
            var authentication = await _jwtTokenService.RefreshAsync(model.AccessToken, model.RefreshToken);

            if (authentication.InvalidCredentials || authentication.AuthenticationRequired)
            {
                return(StatusCode((int)HttpStatusCode.Unauthorized));
            }

            return(Json(authentication));
        }
コード例 #6
0
            public async Task PayloadPreenchido_UsuarioSenhaValidos_UsuarioEncontrado_UsuarioHabilitado_RetornaOk(AuthenticationInputDto authenticationInputDto, JwtAuthenticationResult jwtAuthenticationResult)
            {
                jwtAuthenticationServiceMock.Setup(mock => mock.AuthenticateAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(jwtAuthenticationResult);

                HttpResponseMessage response = await httpClient.PostAsJsonAsync($"{endpointUri}/Authenticate", authenticationInputDto);

                bool wasDeserializationSuccessful = response.Content.TryGetContentValue(out JwtAuthenticationResultDto jwtAuthenticationResultDtoReturned);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                Assert.True(wasDeserializationSuccessful);
                Assert.NotNull(jwtAuthenticationResultDtoReturned);
                jwtAuthenticationServiceMock.Verify(mock => mock.AuthenticateAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            }
コード例 #7
0
 public Task UpdateTokenStoreAsync(JwtAuthenticationResult authenticationResult)
 {
     _accessToken  = authenticationResult.AccessToken;
     _refreshToken = authenticationResult.RefreshToken;
     return(Task.CompletedTask);
 }