public async Task <IReadOnlyCollection <CertificateAuthority> > GetAsync(string accessToken, CancellationToken token) { try { var requestArgs = new TokenSendRequestArgs(_requestUri, accessToken: accessToken); var response = await _client.SendRequestAsync(requestArgs, token); var clientAssertion = _jwtTokenParser.Parse(response); if (!_tokenResponseValidator.IsValid(clientAssertion)) { throw new UnsuccessfulResponseException("Token which was retrieved from SO is corrupted."); } return(TokenConvert.DeserializeClaim <List <CertificateAuthority> >( clientAssertion.JwtSecurityToken, "trusted_list")); } catch (UnsuccessfulResponseException) { throw; } catch (Exception e) { throw new UnsuccessfulResponseException("Trusted list request was unsuccessful.", e); } }
public async Task <CapabilitiesResponse> GetAsync(CapabilitiesRequestArgs args, CancellationToken token) { try { var requestArgs = new TokenSendRequestArgs(args.RequestUri, accessToken: args.AccessToken); var response = await _client.SendRequestAsync(requestArgs, token); var assertionModel = _jwtTokenParser.Parse(response); var validationArgs = CreateValidationArgs(args, assertionModel); if (!await _tokenResponseValidator.IsValidAsync(validationArgs, args.SchemeOwnerAccessToken, token)) { throw new UnsuccessfulResponseException($"Token which was retrieved from {args.RequestUri} is corrupted."); } return(TokenConvert.DeserializeClaim <CapabilitiesResponse>( assertionModel.JwtSecurityToken, "capabilities_info")); } catch (UnsuccessfulResponseException) { throw; } catch (Exception e) { throw new UnsuccessfulResponseException("Capabilities request was unsuccessful.", e); } }
public async Task <PartiesResponse> GetAsync(PartiesRequestArgs args, CancellationToken token) { try { var requestArgs = MapIntoTokenSendRequestArgs(args); var response = await _client.SendRequestAsync(requestArgs, token); var clientAssertion = _jwtTokenParser.Parse(response); if (!_tokenResponseValidator.IsValid(clientAssertion)) { throw new UnsuccessfulResponseException("Token which was retrieved from SO is corrupted."); } return(TokenConvert.DeserializeClaim <PartiesResponse>(clientAssertion.JwtSecurityToken, "parties_info")); } catch (UnsuccessfulResponseException) { throw; } catch (Exception e) { throw new UnsuccessfulResponseException("Parties request was unsuccessful.", e); } }
public void Parse_InvalidInput_Throws(string jwtToken) { Action act = () => _sut.Parse(jwtToken); act.Should().Throw <ArgumentNullException>(); }