Search in sources :

Example 21 with FacebookProfile

use of org.pac4j.oauth.profile.facebook.FacebookProfile in project pac4j by pac4j.

the class JwtTests method testPemJwt.

@Test
public void testPemJwt() throws NoSuchAlgorithmException {
    final FacebookProfile profile = createProfile();
    final ECSignatureConfiguration signatureConfiguration = buildECSignatureConfiguration();
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(signatureConfiguration);
    final String token = generator.generate(profile);
    final JwtAuthenticator authenticator = new JwtAuthenticator();
    authenticator.addSignatureConfiguration(signatureConfiguration);
    assertToken(profile, token, authenticator);
}
Also used : JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) ECSignatureConfiguration(org.pac4j.jwt.config.signature.ECSignatureConfiguration) JwtAuthenticator(org.pac4j.jwt.credentials.authenticator.JwtAuthenticator) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) Test(org.junit.Test)

Example 22 with FacebookProfile

use of org.pac4j.oauth.profile.facebook.FacebookProfile in project pac4j by pac4j.

the class JwtTests method createProfile.

private FacebookProfile createProfile() {
    final FacebookProfile profile = new FacebookProfile();
    profile.setId(ID);
    profile.addAttribute(FacebookProfileDefinition.NAME, NAME);
    profile.addAttribute(FacebookProfileDefinition.VERIFIED, true);
    return profile;
}
Also used : FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile)

Example 23 with FacebookProfile

use of org.pac4j.oauth.profile.facebook.FacebookProfile in project cas by apereo.

the class DelegatedClientAuthenticationHandlerTests method verifyOkWithSimpleIdentifier.

@Test
public void verifyOkWithSimpleIdentifier() throws GeneralSecurityException, PreventedException {
    this.handler.setTypedIdUsed(false);
    val facebookProfile = new FacebookProfile();
    facebookProfile.setId(ID);
    this.fbClient.setProfileCreator((oAuth20Credentials, webContext, sessionStore) -> Optional.of(facebookProfile));
    val result = this.handler.authenticate(this.clientCredential);
    val principal = result.getPrincipal();
    assertEquals(ID, principal.getId());
}
Also used : lombok.val(lombok.val) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) Test(org.junit.jupiter.api.Test)

Example 24 with FacebookProfile

use of org.pac4j.oauth.profile.facebook.FacebookProfile in project cas by apereo.

the class DelegatedClientAuthenticationHandlerTests method verifyMissingClient.

@Test
public void verifyMissingClient() {
    val facebookProfile = new FacebookProfile();
    facebookProfile.setId(ID);
    this.fbClient.setProfileCreator((oAuth20Credentials, webContext, sessionStore) -> Optional.of(facebookProfile));
    val cc = new ClientCredential(new AnonymousCredentials(), "UnknownClient");
    assertThrows(PreventedException.class, () -> this.handler.authenticate(cc));
}
Also used : lombok.val(lombok.val) ClientCredential(org.apereo.cas.authentication.principal.ClientCredential) AnonymousCredentials(org.pac4j.core.credentials.AnonymousCredentials) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) Test(org.junit.jupiter.api.Test)

Aggregations

FacebookProfile (org.pac4j.oauth.profile.facebook.FacebookProfile)24 Test (org.junit.Test)19 JwtGenerator (org.pac4j.jwt.profile.JwtGenerator)17 JwtAuthenticator (org.pac4j.jwt.credentials.authenticator.JwtAuthenticator)11 SecretSignatureConfiguration (org.pac4j.jwt.config.signature.SecretSignatureConfiguration)9 SecretEncryptionConfiguration (org.pac4j.jwt.config.encryption.SecretEncryptionConfiguration)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 lombok.val (lombok.val)3 Test (org.junit.jupiter.api.Test)3 CredentialsException (org.pac4j.core.exception.CredentialsException)3 TechnicalException (org.pac4j.core.exception.TechnicalException)3 ECSignatureConfiguration (org.pac4j.jwt.config.signature.ECSignatureConfiguration)3 AuthenticationHandlerExecutionResult (org.apereo.cas.authentication.AuthenticationHandlerExecutionResult)2 Principal (org.apereo.cas.authentication.principal.Principal)2 TokenCredentials (org.pac4j.core.credentials.TokenCredentials)2 CommonProfile (org.pac4j.core.profile.CommonProfile)2 EncryptionConfiguration (org.pac4j.jwt.config.encryption.EncryptionConfiguration)2 SignatureConfiguration (org.pac4j.jwt.config.signature.SignatureConfiguration)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 ClientCredential (org.apereo.cas.authentication.principal.ClientCredential)1