Search in sources :

Example 11 with FacebookProfile

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

the class DelegatedClientAuthenticationHandlerTests method verifyOk.

@Test
public void verifyOk() throws GeneralSecurityException, PreventedException {
    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(FacebookProfile.class.getName() + '#' + ID, principal.getId());
}
Also used : lombok.val(lombok.val) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) Test(org.junit.jupiter.api.Test)

Example 12 with FacebookProfile

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

the class JwtTests method testPlainJwtNotExpired.

@Test
public void testPlainJwtNotExpired() {
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>();
    Map<String, Object> claims = new HashMap<>();
    claims.put(JwtClaims.SUBJECT, ID);
    claims.put(JwtClaims.EXPIRATION_TIME, tomorrow());
    final String token = generator.generate(claims);
    JwtAuthenticator authenticator = new JwtAuthenticator();
    assertNotNull(authenticator.validateToken(token));
}
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)

Example 13 with FacebookProfile

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

the class JwtTests method testPlainJwtWithoutSignatureConfigurations.

@Test
public void testPlainJwtWithoutSignatureConfigurations() {
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>();
    final FacebookProfile profile = createProfile();
    final String token = generator.generate(profile);
    assertToken(profile, token, new JwtAuthenticator());
}
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)

Example 14 with FacebookProfile

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

the class JwtTests method testDoubleGenerateAuthenticate.

@Test
public void testDoubleGenerateAuthenticate() {
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(new SecretSignatureConfiguration(MAC_SECRET), new SecretEncryptionConfiguration(MAC_SECRET));
    final FacebookProfile profile = createProfile();
    final String token = generator.generate(profile);
    final JwtAuthenticator authenticator = new JwtAuthenticator(new SecretSignatureConfiguration(MAC_SECRET), new SecretEncryptionConfiguration(MAC_SECRET));
    final TokenCredentials credentials = new TokenCredentials(token);
    authenticator.validate(credentials, null);
    final FacebookProfile profile2 = (FacebookProfile) credentials.getUserProfile();
    generator.generate(profile2);
}
Also used : JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) JwtAuthenticator(org.pac4j.jwt.credentials.authenticator.JwtAuthenticator) SecretEncryptionConfiguration(org.pac4j.jwt.config.encryption.SecretEncryptionConfiguration) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) SecretSignatureConfiguration(org.pac4j.jwt.config.signature.SecretSignatureConfiguration) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 15 with FacebookProfile

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

the class JwtTests method testGenerateAuthenticateSub.

@Test(expected = TechnicalException.class)
public void testGenerateAuthenticateSub() {
    final JwtGenerator<FacebookProfile> generator = new JwtGenerator<>(new SecretSignatureConfiguration(MAC_SECRET));
    final FacebookProfile profile = createProfile();
    profile.addAttribute(JwtClaims.SUBJECT, VALUE);
    final String token = generator.generate(profile);
    assertToken(profile, token);
}
Also used : JwtGenerator(org.pac4j.jwt.profile.JwtGenerator) FacebookProfile(org.pac4j.oauth.profile.facebook.FacebookProfile) SecretSignatureConfiguration(org.pac4j.jwt.config.signature.SecretSignatureConfiguration) 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