Search in sources :

Example 1 with FacebookProfile

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

the class ClientAuthenticationHandlerTests method verifyOkWithSimpleIdentifier.

@Test
public void verifyOkWithSimpleIdentifier() throws GeneralSecurityException, PreventedException {
    this.handler.setTypedIdUsed(false);
    final FacebookProfile facebookProfile = new FacebookProfile();
    facebookProfile.setId(ID);
    this.fbClient.setProfileCreator((oAuth20Credentials, webContext) -> facebookProfile);
    final AuthenticationHandlerExecutionResult result = this.handler.authenticate(this.clientCredential);
    final Principal principal = result.getPrincipal();
    assertEquals(ID, principal.getId());
}
Also used : AuthenticationHandlerExecutionResult(org.apereo.cas.authentication.AuthenticationHandlerExecutionResult) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) Principal(org.apereo.cas.authentication.principal.Principal) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with FacebookProfile

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

the class ClientAuthenticationHandlerTests method verifyOk.

@Test
public void verifyOk() throws GeneralSecurityException, PreventedException {
    final FacebookProfile facebookProfile = new FacebookProfile();
    facebookProfile.setId(ID);
    this.fbClient.setProfileCreator((oAuth20Credentials, webContext) -> facebookProfile);
    final AuthenticationHandlerExecutionResult result = this.handler.authenticate(this.clientCredential);
    final Principal principal = result.getPrincipal();
    assertEquals(FacebookProfile.class.getName() + '#' + ID, principal.getId());
}
Also used : AuthenticationHandlerExecutionResult(org.apereo.cas.authentication.AuthenticationHandlerExecutionResult) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) Principal(org.apereo.cas.authentication.principal.Principal) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with FacebookProfile

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

the class JwtTests method testGenerateAuthenticateDifferentSecrets.

@Test
public void testGenerateAuthenticateDifferentSecrets() {
    final SignatureConfiguration signatureConfiguration = new SecretSignatureConfiguration(MAC_SECRET);
    final EncryptionConfiguration encryptionConfiguration = new SecretEncryptionConfiguration(KEY2);
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(signatureConfiguration, encryptionConfiguration);
    final FacebookProfile profile = createProfile();
    final String token = generator.generate(profile);
    assertToken(profile, token, new JwtAuthenticator(signatureConfiguration, encryptionConfiguration));
}
Also used : JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) SecretSignatureConfiguration(org.pac4j.jwt.config.signature.SecretSignatureConfiguration) SignatureConfiguration(org.pac4j.jwt.config.signature.SignatureConfiguration) ECSignatureConfiguration(org.pac4j.jwt.config.signature.ECSignatureConfiguration) SecretEncryptionConfiguration(org.pac4j.jwt.config.encryption.SecretEncryptionConfiguration) EncryptionConfiguration(org.pac4j.jwt.config.encryption.EncryptionConfiguration) JwtAuthenticator(org.pac4j.jwt.credentials.authenticator.JwtAuthenticator) SecretEncryptionConfiguration(org.pac4j.jwt.config.encryption.SecretEncryptionConfiguration) SecretSignatureConfiguration(org.pac4j.jwt.config.signature.SecretSignatureConfiguration) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) Test(org.junit.Test)

Example 4 with FacebookProfile

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

the class JwtTests method assertToken.

private CommonProfile assertToken(FacebookProfile profile, String token, JwtAuthenticator authenticator) {
    final TokenCredentials credentials = new TokenCredentials(token);
    authenticator.validate(credentials, null);
    final CommonProfile profile2 = credentials.getUserProfile();
    assertTrue(profile2 instanceof FacebookProfile);
    final FacebookProfile fbProfile = (FacebookProfile) profile2;
    assertEquals(profile.getTypedId(), fbProfile.getTypedId());
    assertEquals(profile.getFirstName(), fbProfile.getFirstName());
    assertEquals(profile.getDisplayName(), fbProfile.getDisplayName());
    assertEquals(profile.getFamilyName(), fbProfile.getFamilyName());
    assertEquals(profile.getVerified(), fbProfile.getVerified());
    return profile2;
}
Also used : CommonProfile(org.pac4j.core.profile.CommonProfile) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) TokenCredentials(org.pac4j.core.credentials.TokenCredentials)

Example 5 with FacebookProfile

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

the class JwtTests method testPlainJwtNoSubject.

@Test
public void testPlainJwtNoSubject() {
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>();
    final String token = generator.generate(new HashMap<>());
    JwtAuthenticator authenticator = new JwtAuthenticator();
    TestsHelper.expectException(() -> authenticator.validateToken(token), TechnicalException.class, "JWT must contain a subject ('sub' claim)");
}
Also used : JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) JwtAuthenticator(org.pac4j.jwt.credentials.authenticator.JwtAuthenticator) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) Test(org.junit.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