Search in sources :

Example 61 with AuthenticationRequest

use of com.nimbusds.openid.connect.sdk.AuthenticationRequest in project di-authentication-api by alphagov.

the class MfaHelper method mfaRequired.

public static boolean mfaRequired(Map<String, List<String>> authRequestParams) {
    AuthenticationRequest authRequest;
    try {
        authRequest = AuthenticationRequest.parse(authRequestParams);
    } catch (ParseException e) {
        throw new RuntimeException();
    }
    List<String> vtr = authRequest.getCustomParameter("vtr");
    VectorOfTrust vectorOfTrust = VectorOfTrust.parseFromAuthRequestAttribute(vtr);
    return !vectorOfTrust.getCredentialTrustLevel().equals(LOW_LEVEL);
}
Also used : VectorOfTrust(uk.gov.di.authentication.shared.entity.VectorOfTrust) ParseException(com.nimbusds.oauth2.sdk.ParseException) AuthenticationRequest(com.nimbusds.openid.connect.sdk.AuthenticationRequest)

Example 62 with AuthenticationRequest

use of com.nimbusds.openid.connect.sdk.AuthenticationRequest in project di-authentication-api by alphagov.

the class LoginHandlerTest method generateAuthRequest.

private AuthenticationRequest generateAuthRequest() {
    Scope scope = new Scope();
    scope.add(OIDCScopeValue.OPENID);
    AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(ResponseType.CODE, scope, CLIENT_ID, URI.create("http://localhost/redirect")).state(new State()).nonce(new Nonce());
    return builder.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)

Example 63 with AuthenticationRequest

use of com.nimbusds.openid.connect.sdk.AuthenticationRequest in project di-authentication-api by alphagov.

the class MfaHandlerTest 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 64 with AuthenticationRequest

use of com.nimbusds.openid.connect.sdk.AuthenticationRequest in project di-authentication-api by alphagov.

the class UpdateProfileIntegrationTest method shouldCallUpdateProfileToUpdateConsentAndReturn200.

@Test
public void shouldCallUpdateProfileToUpdateConsentAndReturn200() throws Json.JsonException {
    String sessionId = redis.createSession();
    String clientSessionId = IdGenerator.generate();
    AuthenticationRequest authRequest = setUpTest(sessionId, clientSessionId);
    redis.createClientSession(clientSessionId, authRequest.toParameters());
    UpdateProfileRequest request = new UpdateProfileRequest(EMAIL_ADDRESS, CAPTURE_CONSENT, String.valueOf(true));
    var response = makeRequest(Optional.of(request), constructFrontendHeaders(sessionId, clientSessionId), Map.of());
    assertThat(response, hasStatus(204));
    Optional<ClientConsent> consent = userStore.getUserConsents(EMAIL_ADDRESS).flatMap(list -> list.stream().filter(c -> c.getClientId().equals(CLIENT_ID)).findFirst());
    assertTrue(consent.get().getClaims().containsAll(OIDCScopeValue.OPENID.getClaimNames()));
    assertTrue(consent.get().getClaims().containsAll(OIDCScopeValue.EMAIL.getClaimNames()));
    assertEventTypesReceived(auditTopic, List.of(UPDATE_PROFILE_REQUEST_RECEIVED, UPDATE_PROFILE_REQUEST_RECEIVED));
}
Also used : UpdateProfileRequest(uk.gov.di.authentication.frontendapi.entity.UpdateProfileRequest) AuthenticationRequest(com.nimbusds.openid.connect.sdk.AuthenticationRequest) ClientConsent(uk.gov.di.authentication.shared.entity.ClientConsent) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ApiGatewayHandlerIntegrationTest(uk.gov.di.authentication.sharedtest.basetest.ApiGatewayHandlerIntegrationTest)

Example 65 with AuthenticationRequest

use of com.nimbusds.openid.connect.sdk.AuthenticationRequest in project di-authentication-api by alphagov.

the class UpdateProfileIntegrationTest method setUpTest.

private AuthenticationRequest setUpTest(String sessionId, String clientSessionId) throws Json.JsonException {
    Scope scope = new Scope();
    scope.add(OIDCScopeValue.OPENID);
    scope.add(OIDCScopeValue.EMAIL);
    redis.addEmailToSession(sessionId, EMAIL_ADDRESS);
    AuthenticationRequest authRequest = new AuthenticationRequest.Builder(ResponseType.CODE, scope, new ClientID(CLIENT_ID), URI.create("http://localhost/redirect")).nonce(new Nonce()).build();
    redis.createClientSession(clientSessionId, authRequest.toParameters());
    clientStore.registerClient(CLIENT_ID, "test-client", singletonList("redirect-url"), singletonList(EMAIL_ADDRESS), List.of("openid", "email"), "public-key", singletonList("http://localhost/post-redirect-logout"), "http://example.com", String.valueOf(ServiceType.MANDATORY), "https://test.com", "public", true);
    Set<String> claims = ValidScopes.getClaimsForListOfScopes(scope.toStringList());
    userStore.signUp(EMAIL_ADDRESS, "password");
    userStore.updateConsent(EMAIL_ADDRESS, new ClientConsent(CLIENT_ID, claims, LocalDateTime.now(ZoneId.of("UTC")).toString()));
    return authRequest;
}
Also used : Nonce(com.nimbusds.openid.connect.sdk.Nonce) Scope(com.nimbusds.oauth2.sdk.Scope) ClientID(com.nimbusds.oauth2.sdk.id.ClientID) AuthenticationRequest(com.nimbusds.openid.connect.sdk.AuthenticationRequest) ClientConsent(uk.gov.di.authentication.shared.entity.ClientConsent)

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