public async Task <JwsPayload> UnSign(string jws) { if (string.IsNullOrWhiteSpace(jws)) { throw new ArgumentNullException(nameof(jws)); } var protectedHeader = _jwsParser.GetHeader(jws); if (protectedHeader == null) { return(null); } var jsonWebKeySet = await _identityServerClientFactory.CreateJwksClient() .ResolveAsync(_parametersProvider.GetOpenIdConfigurationUrl()) .ConfigureAwait(false); var jsonWebKeys = _jsonWebKeyConverter.ExtractSerializedKeys(jsonWebKeySet); if (jsonWebKeys == null || !jsonWebKeys.Any(j => j.Kid == protectedHeader.Kid)) { return(null); } var jsonWebKey = jsonWebKeys.First(j => j.Kid == protectedHeader.Kid); if (protectedHeader.Alg == Jwt.Constants.JwsAlgNames.NONE) { return(_jwsParser.GetPayload(jws)); } return(_jwsParser.ValidateSignature(jws, jsonWebKey)); }
public async Task <JwsPayload> UnSign(string jws, string openidProvider) { if (string.IsNullOrWhiteSpace(jws)) { throw new ArgumentNullException(nameof(jws)); } if (string.IsNullOrWhiteSpace(openidProvider)) { throw new ArgumentNullException(nameof(openidProvider)); } var protectedHeader = _jwsParser.GetHeader(jws); if (protectedHeader == null) { return(null); } if (protectedHeader.Alg == SimpleIdServer.Core.Jwt.Constants.JwsAlgNames.NONE) { return(_jwsParser.GetPayload(jws)); } var jsonWebKeySet = await _identityServerClientFactory.CreateJwksClient().ResolveAsync(openidProvider).ConfigureAwait(false); return(_jwsParser.ValidateSignature(jws, jsonWebKeySet)); }