protected Task <IPrincipal> AuthJwtToken(string token) { IEnumerable <Claim> claims; if (JwtTokenManager.ValidateToken(token, _Configuration.GetSection("JWTAudience").Key, _Configuration.GetSection("SelfAddress").Key, out claims)) { var identity = new ClaimsIdentity(claims.ToList(), "Jwt"); IPrincipal user = new ClaimsPrincipal(identity); return(Task.FromResult(user)); } return(Task.FromResult <IPrincipal>(null)); }
public VerifyResponse Verify([FromBody] VerifyRequest verifyRequest) { var response = new VerifyResponse(); try { if (verifyRequest == null || string.IsNullOrWhiteSpace(verifyRequest.Token)) { throw new APIException("Token cannot be null"); } LoginResponse loginResponse = null; loginResponse = Storage.IssuedTokens.SingleOrDefault(t => t.Token == verifyRequest.Token); if (loginResponse != null) { if (JwtTokenManager.ValidateToken(loginResponse.Token)) { response.IsSuccess = true; } else { response.IsSuccess = false; response.ErrorMessage = "Invalid token."; } } else { response.IsSuccess = false; response.ErrorMessage = "User not authenticated."; } } catch (Exception ex) { response.IsSuccess = false; response.ErrorMessage = "Verification failed."; LogException(IdentityServer.API.EventIds.Verify, ex); } return(response); }
public void Receive(AuthenticationTokenReceiveContext context) { var principal = JwtTokenManager.ValidateToken(context.Token); context.DeserializeTicket(context.Token); }