public static JweInformationResponse ToDto(this JweInformationResult jweInformationResult) { return(new JweInformationResponse { IsContentJws = jweInformationResult.IsContentJws, Content = jweInformationResult.Content }); }
public async Task <JweInformationResult> ExecuteAsync(GetJweParameter getJweParameter) { if (getJweParameter == null) { throw new ArgumentNullException(nameof(getJweParameter)); } if (string.IsNullOrWhiteSpace(getJweParameter.Jwe)) { throw new ArgumentNullException(nameof(getJweParameter.Jwe)); } if (string.IsNullOrWhiteSpace(getJweParameter.Url)) { throw new ArgumentNullException(nameof(getJweParameter.Url)); } Uri uri = null; if (!Uri.TryCreate(getJweParameter.Url, UriKind.Absolute, out uri)) { throw new IdentityServerManagerException( ErrorCodes.InvalidRequestCode, string.Format(ErrorDescriptions.TheUrlIsNotWellFormed, getJweParameter.Url)); } var jwe = getJweParameter.Jwe; var jweHeader = _jweParser.GetHeader(jwe); if (jweHeader == null) { throw new IdentityServerManagerException( ErrorCodes.InvalidRequestCode, ErrorDescriptions.TheTokenIsNotAValidJwe); } var jsonWebKey = await _jsonWebKeyHelper.GetJsonWebKey(jweHeader.Kid, uri).ConfigureAwait(false); if (jsonWebKey == null) { throw new IdentityServerManagerException( ErrorCodes.InvalidRequestCode, string.Format(ErrorDescriptions.TheJsonWebKeyCannotBeFound, jweHeader.Kid, uri.AbsoluteUri)); } var content = string.Empty; if (!string.IsNullOrWhiteSpace(getJweParameter.Password)) { content = _jweParser.ParseByUsingSymmetricPassword(jwe, jsonWebKey, getJweParameter.Password); } else { content = _jweParser.Parse(jwe, jsonWebKey); } if (string.IsNullOrWhiteSpace(content)) { throw new IdentityServerManagerException( ErrorCodes.InvalidRequestCode, ErrorDescriptions.TheContentCannotBeExtractedFromJweToken); } var result = new JweInformationResult { Content = content, IsContentJws = false }; var jwsHeader = _jwsParser.GetHeader(content); if (jwsHeader != null) { result.IsContentJws = true; } return(result); }