use of com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse in project openbanking-aspsp by OpenBankingToolkit.
the class ASDiscoveryService method discovery.
public OIDCDiscoveryResponse discovery(String oidcRootEndpoint) {
String wellKnownEndpoint = oidcRootEndpoint + OIDCConstants.Endpoint.WELL_KNOWN;
LOGGER.debug("Call the well-known endpoint of the AS {}", wellKnownEndpoint);
ParameterizedTypeReference<OIDCDiscoveryResponse> ptr = new ParameterizedTypeReference<OIDCDiscoveryResponse>() {
};
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(wellKnownEndpoint);
URI uri = builder.build().encode().toUri();
ResponseEntity<OIDCDiscoveryResponse> entity = restTemplate.exchange(uri, HttpMethod.GET, null, ptr);
return entity.getBody();
}
use of com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse in project openbanking-aspsp by OpenBankingToolkit.
the class DiscoveryApiControllerTest method requireRequestUriRegistration_isNull_when_requestUriParameterNotSupported.
@Test
public void requireRequestUriRegistration_isNull_when_requestUriParameterNotSupported() throws OBErrorResponseException {
// Given
MockHttpServletRequest req = new MockHttpServletRequest();
OIDCDiscoveryResponse oidcDiscoveryResponse = JMockData.mock(OIDCDiscoveryResponse.class);
oidcDiscoveryResponse.setRequireRequestUriRegistration(true);
oidcDiscoveryResponse.setRequestUriParameterSupported(false);
ResponseEntity<OIDCDiscoveryResponse> response = new ResponseEntity<>(oidcDiscoveryResponse, HttpStatus.OK);
given(amGateway.toAM(req, new HttpHeaders(), new ParameterizedTypeReference<OIDCDiscoveryResponse>() {
})).willReturn(response);
// When
ResponseEntity<OIDCDiscoveryResponse> discovery = discoveryApiController.getDiscovery(req);
// Then
OIDCDiscoveryResponse respBody = Objects.requireNonNull(discovery.getBody());
assertThat(respBody.getRequestUriParameterSupported()).isFalse();
assertThat(respBody.getRequireRequestUriRegistration()).isNull();
}
use of com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse in project openbanking-aspsp by OpenBankingToolkit.
the class DiscoveryApiControllerTest method testResponseTypesSupported_dont_match.
@Test
public void testResponseTypesSupported_dont_match() {
// Given
List<String> responseTypes = List.of("code", "id_token", "code id_token");
given(config.getSupportedResponseTypes()).willReturn(responseTypes);
discoveryApiController = new DiscoveryApiController(amGateway, config, "localhost", "", "", "");
MockHttpServletRequest req = new MockHttpServletRequest();
OIDCDiscoveryResponse oidcDiscoveryResponse = JMockData.mock(OIDCDiscoveryResponse.class);
List<String> amResponseTypes = new ArrayList<>();
amResponseTypes.addAll(responseTypes.subList(0, 1));
amResponseTypes.add("device_code");
amResponseTypes.add("device_code code id_token");
oidcDiscoveryResponse.setResponseTypesSupported(amResponseTypes);
ResponseEntity<OIDCDiscoveryResponse> response = new ResponseEntity<>(oidcDiscoveryResponse, HttpStatus.OK);
given(amGateway.toAM(req, new HttpHeaders(), new ParameterizedTypeReference<OIDCDiscoveryResponse>() {
})).willReturn(response);
// When
OBErrorResponseException e = catchThrowableOfType(() -> discoveryApiController.getDiscovery(req), OBErrorResponseException.class);
// Then
assertThat(e.getErrors().get(0).getMessage()).isEqualTo("The response types supported by the authorisation server '" + amResponseTypes + "' don't match with the response types supported '" + responseTypes + "' by as-api");
assertThat(e.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST);
}
use of com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse in project openbanking-aspsp by OpenBankingToolkit.
the class DiscoveryApiControllerTest method testResponseTypeSupported_dont_match.
@Test
public void testResponseTypeSupported_dont_match() {
// Given
List<String> responseTypes = List.of("code id_token");
given(config.getSupportedResponseTypes()).willReturn(responseTypes);
discoveryApiController = new DiscoveryApiController(amGateway, config, "localhost", "", "", "");
MockHttpServletRequest req = new MockHttpServletRequest();
OIDCDiscoveryResponse oidcDiscoveryResponse = JMockData.mock(OIDCDiscoveryResponse.class);
List<String> amResponseTypes = List.of("device_code", "device_code code id_token");
oidcDiscoveryResponse.setResponseTypesSupported(amResponseTypes);
ResponseEntity<OIDCDiscoveryResponse> response = new ResponseEntity<>(oidcDiscoveryResponse, HttpStatus.OK);
given(amGateway.toAM(req, new HttpHeaders(), new ParameterizedTypeReference<OIDCDiscoveryResponse>() {
})).willReturn(response);
// When
OBErrorResponseException e = catchThrowableOfType(() -> discoveryApiController.getDiscovery(req), OBErrorResponseException.class);
// Then
assertThat(e.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(e.getErrors().get(0).getMessage()).isEqualTo("The response types supported by the authorisation server '" + amResponseTypes + "' don't match with the response types supported '" + responseTypes + "' by as-api");
}
use of com.forgerock.openbanking.common.model.as.discovery.OIDCDiscoveryResponse in project openbanking-aspsp by OpenBankingToolkit.
the class DiscoveryApiControllerTest method testCustomAPIVersion.
@Test
public void testCustomAPIVersion() throws OBErrorResponseException {
// Given
discoveryApiController = new DiscoveryApiController(amGateway, config, "localhost", "8074", "RWApiVersion", "CRApiVersion");
MockHttpServletRequest req = new MockHttpServletRequest();
OIDCDiscoveryResponse oidcDiscoveryResponse = JMockData.mock(OIDCDiscoveryResponse.class);
ResponseEntity<OIDCDiscoveryResponse> response = new ResponseEntity<>(oidcDiscoveryResponse, HttpStatus.OK);
given(amGateway.toAM(req, new HttpHeaders(), new ParameterizedTypeReference<OIDCDiscoveryResponse>() {
})).willReturn(response);
// When
ResponseEntity<OIDCDiscoveryResponse> discovery = discoveryApiController.getDiscovery(req);
// Then
assertThat(discovery.getBody().getReadWriteApiVersion()).isEqualTo("RWApiVersion");
assertThat(discovery.getBody().getClientRegistrationApiVersion()).isEqualTo("CRApiVersion");
}
Aggregations