use of com.nimbusds.openid.connect.sdk.AuthenticationRequest in project di-authentication-api by alphagov.
the class SignupIntegrationTest method shouldReturn200WhenValidSignUpRequest.
@ParameterizedTest
@MethodSource("consentValues")
void shouldReturn200WhenValidSignUpRequest(boolean consentRequired) throws IOException, Json.JsonException {
String sessionId = redis.createSession();
Map<String, String> headers = new HashMap<>();
headers.put("Session-Id", sessionId);
headers.put("Client-Session-Id", CLIENT_SESSION_ID);
headers.put("X-API-Key", FRONTEND_API_KEY);
Scope scope = new Scope();
scope.add(OIDCScopeValue.OPENID);
AuthenticationRequest authRequest = new AuthenticationRequest.Builder(ResponseType.CODE, scope, new ClientID(CLIENT_ID), URI.create(REDIRECT_URI)).nonce(new Nonce()).build();
redis.createClientSession(CLIENT_SESSION_ID, authRequest.toParameters());
clientStore.registerClient(CLIENT_ID, "The test client", singletonList(REDIRECT_URI), singletonList("test-client@test.com"), singletonList(scope.toString()), Base64.getMimeEncoder().encodeToString(GENERATE_RSA_KEY_PAIR().getPublic().getEncoded()), singletonList("http://localhost/post-redirect-logout"), "http://example.com", String.valueOf(ServiceType.MANDATORY), "https://test.com", "public", consentRequired);
var response = makeRequest(Optional.of(new SignupRequest("joe.bloggs+5@digital.cabinet-office.gov.uk", "password-1")), headers, Map.of());
assertThat(response, hasStatus(200));
SignUpResponse signUpResponse = objectMapper.readValue(response.getBody(), SignUpResponse.class);
assertThat(signUpResponse.isConsentRequired(), equalTo(consentRequired));
assertTrue(userStore.userExists("joe.bloggs+5@digital.cabinet-office.gov.uk"));
assertEventTypesReceived(auditTopic, List.of(CREATE_ACCOUNT));
}
use of com.nimbusds.openid.connect.sdk.AuthenticationRequest in project di-authentication-api by alphagov.
the class IPVAuthorisationHandlerIntegrationTest method withAuthenticationRequest.
private AuthenticationRequest withAuthenticationRequest(String clientId) {
Scope scope = new Scope();
scope.add(OIDCScopeValue.OPENID);
return new AuthenticationRequest.Builder(new ResponseType(ResponseType.Value.CODE), scope, new ClientID(clientId), REDIRECT_URI).state(new State()).nonce(new Nonce()).build();
}
use of com.nimbusds.openid.connect.sdk.AuthenticationRequest in project di-authentication-api by alphagov.
the class LoginIntegrationTest method shouldSuccessfullyProcessLoginRequestForDifferentVectorOfTrusts.
@ParameterizedTest
@MethodSource("vectorOfTrust")
void shouldSuccessfullyProcessLoginRequestForDifferentVectorOfTrusts(CredentialTrustLevel level, String termsAndConditionsVersion) throws Json.JsonException {
String email = "joe.bloggs+3@digital.cabinet-office.gov.uk";
String password = "password-1";
String phoneNumber = "01234567890";
userStore.signUp(email, password);
userStore.addPhoneNumber(email, phoneNumber);
userStore.updateTermsAndConditions(email, termsAndConditionsVersion);
String sessionId = redis.createSession();
Scope scope = new Scope();
scope.add(OIDCScopeValue.OPENID);
AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(ResponseType.CODE, scope, new ClientID(CLIENT_ID), URI.create(REDIRECT_URI)).nonce(new Nonce());
if (level != null) {
builder.customParameter("vtr", jsonArrayOf(level.getValue()));
}
AuthenticationRequest authRequest = builder.build();
redis.createClientSession(CLIENT_SESSION_ID, authRequest.toParameters());
clientStore.registerClient(CLIENT_ID, "The test client", singletonList(REDIRECT_URI), singletonList("test-client@test.com"), singletonList(scope.toString()), Base64.getMimeEncoder().encodeToString(GENERATE_RSA_KEY_PAIR().getPublic().getEncoded()), singletonList("http://localhost/post-redirect-logout"), "http://example.com", String.valueOf(ServiceType.MANDATORY), "https://test.com", "public", true);
Map<String, String> headers = new HashMap<>();
headers.put("Session-Id", sessionId);
headers.put("X-API-Key", FRONTEND_API_KEY);
headers.put("Client-Session-Id", CLIENT_SESSION_ID);
var response = makeRequest(Optional.of(new LoginRequest(email, password)), headers, Map.of());
assertThat(response, hasStatus(200));
LoginResponse loginResponse = objectMapper.readValue(response.getBody(), LoginResponse.class);
assertThat(loginResponse.isMfaRequired(), equalTo(level != LOW_LEVEL));
assertThat(loginResponse.getLatestTermsAndConditionsAccepted(), equalTo(termsAndConditionsVersion.equals(CURRENT_TERMS_AND_CONDITIONS)));
assertEventTypesReceived(auditTopic, List.of(LOG_IN_SUCCESS));
}
use of com.nimbusds.openid.connect.sdk.AuthenticationRequest in project di-authentication-api by alphagov.
the class DocAppCallbackHandlerTest method generateAuthRequest.
public static AuthenticationRequest generateAuthRequest() {
ResponseType responseType = new ResponseType(ResponseType.Value.CODE);
State state = new State();
Scope scope = new Scope();
Nonce nonce = new Nonce();
scope.add(OIDCScopeValue.OPENID);
scope.add("phone");
scope.add("email");
return new AuthenticationRequest.Builder(responseType, scope, CLIENT_ID, REDIRECT_URI).state(state).nonce(nonce).build();
}
use of com.nimbusds.openid.connect.sdk.AuthenticationRequest in project di-authentication-api by alphagov.
the class AuthorisationHandlerTest method generateAuthRequest.
private AuthenticationRequest generateAuthRequest(Optional<String> credentialTrustLevel) {
Scope scope = new Scope();
scope.add(OIDCScopeValue.OPENID);
AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(ResponseType.CODE, scope, CLIENT_ID, URI.create(REDIRECT_URI)).state(STATE).nonce(new Nonce());
credentialTrustLevel.ifPresent(t -> builder.customParameter("vtr", t));
return builder.build();
}
Aggregations