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);
}
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();
}
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();
}
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));
}
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;
}
Aggregations