Search in sources :

Example 66 with AuthenticationRequest

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));
}
Also used : Nonce(com.nimbusds.openid.connect.sdk.Nonce) SignUpResponse(uk.gov.di.authentication.frontendapi.entity.SignUpResponse) Scope(com.nimbusds.oauth2.sdk.Scope) HashMap(java.util.HashMap) ClientID(com.nimbusds.oauth2.sdk.id.ClientID) SignupRequest(uk.gov.di.authentication.frontendapi.entity.SignupRequest) AuthenticationRequest(com.nimbusds.openid.connect.sdk.AuthenticationRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 67 with AuthenticationRequest

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();
}
Also used : Nonce(com.nimbusds.openid.connect.sdk.Nonce) Scope(com.nimbusds.oauth2.sdk.Scope) State(com.nimbusds.oauth2.sdk.id.State) ClientID(com.nimbusds.oauth2.sdk.id.ClientID) AuthenticationRequest(com.nimbusds.openid.connect.sdk.AuthenticationRequest) ResponseType(com.nimbusds.oauth2.sdk.ResponseType)

Example 68 with AuthenticationRequest

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));
}
Also used : Nonce(com.nimbusds.openid.connect.sdk.Nonce) LoginResponse(uk.gov.di.authentication.frontendapi.entity.LoginResponse) Scope(com.nimbusds.oauth2.sdk.Scope) HashMap(java.util.HashMap) ClientID(com.nimbusds.oauth2.sdk.id.ClientID) LoginRequest(uk.gov.di.authentication.frontendapi.entity.LoginRequest) AuthenticationRequest(com.nimbusds.openid.connect.sdk.AuthenticationRequest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 69 with AuthenticationRequest

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();
}
Also used : Nonce(com.nimbusds.openid.connect.sdk.Nonce) Scope(com.nimbusds.oauth2.sdk.Scope) State(com.nimbusds.oauth2.sdk.id.State) AuthenticationRequest(com.nimbusds.openid.connect.sdk.AuthenticationRequest) ResponseType(com.nimbusds.oauth2.sdk.ResponseType)

Example 70 with AuthenticationRequest

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();
}
Also used : Nonce(com.nimbusds.openid.connect.sdk.Nonce) Scope(com.nimbusds.oauth2.sdk.Scope) AuthenticationRequest(com.nimbusds.openid.connect.sdk.AuthenticationRequest)

Aggregations

AuthenticationRequest (com.nimbusds.openid.connect.sdk.AuthenticationRequest)73 Scope (com.nimbusds.oauth2.sdk.Scope)44 ResponseType (com.nimbusds.oauth2.sdk.ResponseType)34 State (com.nimbusds.oauth2.sdk.id.State)29 Nonce (com.nimbusds.openid.connect.sdk.Nonce)27 ClientID (com.nimbusds.oauth2.sdk.id.ClientID)24 Test (org.junit.jupiter.api.Test)19 ErrorObject (com.nimbusds.oauth2.sdk.ErrorObject)16 URI (java.net.URI)16 ParseException (com.nimbusds.oauth2.sdk.ParseException)12 ClientSession (uk.gov.di.authentication.shared.entity.ClientSession)12 AuthorizationCode (com.nimbusds.oauth2.sdk.AuthorizationCode)11 VectorOfTrust (uk.gov.di.authentication.shared.entity.VectorOfTrust)10 AuthenticationSuccessResponse (com.nimbusds.openid.connect.sdk.AuthenticationSuccessResponse)8 APIGatewayProxyResponseEvent (com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 MethodSource (org.junit.jupiter.params.provider.MethodSource)6 SignedJWT (com.nimbusds.jwt.SignedJWT)5 OIDCClaimsRequest (com.nimbusds.openid.connect.sdk.OIDCClaimsRequest)5 HashMap (java.util.HashMap)5