Search in sources :

Example 11 with UserInfo

use of com.auth0.json.auth.UserInfo in project app-auth0-idprovider by enonic.

the class Auth0CallbackService method handle.

public boolean handle(final HttpServletRequest request) {
    try {
        final IdProviderKey idProviderKey = getIdProviderKey(request);
        final AuthenticationController authController = createAuthController(idProviderKey);
        final Tokens tokens = authController.handle(request);
        final UserInfo userInfo = retrieveUserInfo(idProviderKey, tokens);
        loginService.login(request, new UserInfoAdapter(userInfo), idProviderKey);
        return true;
    } catch (Exception e) {
        LOG.error("Error while handling auth0 callback", e);
    }
    return false;
}
Also used : AuthenticationController(com.auth0.AuthenticationController) IdProviderKey(com.enonic.xp.security.IdProviderKey) UserInfo(com.auth0.json.auth.UserInfo) UserInfoAdapter(com.enonic.app.auth0.impl.user.UserInfoAdapter) Auth0Exception(com.auth0.exception.Auth0Exception) Tokens(com.auth0.Tokens)

Example 12 with UserInfo

use of com.auth0.json.auth.UserInfo in project pic-sure-auth-microapp by hms-dbmi.

the class Auth0MatchingServiceTest method testMatchTokenToUser.

@Test
public void testMatchTokenToUser() {
    String ldapToken = "ldap-connector-access-token";
    String githubToken = "github-access-token";
    String nihToken = "nih-gov-prod-access-token";
    try {
        JsonNode userInfo = mockAuthAPIUserInfo(ldapToken);
        // Test when everything works fine
        User result = cut.matchTokenToUser(userInfo);
        assertNotNull(result);
        assertNotNull(result.getAuth0metadata());
        assertNotNull(result.getSubject());
        assertEquals("ad|ldap-connector|blablablablablablablablablablablabla", result.getSubject());
        assertTrue(result.isMatched());
        assertNotNull(persistedUser);
        assertNotNull(persistedUser.getAuth0metadata());
        assertEquals(persistedUser.getAuth0metadata(), result.getAuth0metadata());
        assertNotNull(persistedUser.getSubject());
        assertEquals("ad|ldap-connector|blablablablablablablablablablablabla", persistedUser.getSubject());
        assertTrue(persistedUser.isMatched());
        // Reset
        persistedUser = null;
        // Test when multiple mappings in database
        userInfo = mockAuthAPIUserInfo(githubToken);
        result = cut.matchTokenToUser(userInfo);
        assertNotNull(result);
        assertNotNull(result.getAuth0metadata());
        assertNotNull(result.getSubject());
        assertEquals("github|0000000", result.getSubject());
        assertTrue(result.isMatched());
        assertNotNull(persistedUser);
        assertNotNull(persistedUser.getAuth0metadata());
        assertEquals(persistedUser.getAuth0metadata(), result.getAuth0metadata());
        assertNotNull(persistedUser.getSubject());
        assertEquals("github|0000000", persistedUser.getSubject());
        assertTrue(persistedUser.isMatched());
        persistedUser = null;
        // Test when path not found in user generalmetadata
        userInfo = mockAuthAPIUserInfo(nihToken);
        result = cut.matchTokenToUser(userInfo);
        assertNotNull(result);
        assertNotNull(result.getAuth0metadata());
        assertNotNull(result.getSubject());
        assertEquals("samlp|NOBODY", result.getSubject());
        assertTrue(result.isMatched());
        assertNotNull(persistedUser);
        assertNotNull(persistedUser.getAuth0metadata());
        assertEquals(persistedUser.getAuth0metadata(), result.getAuth0metadata());
        assertNotNull(persistedUser.getSubject());
        assertEquals("samlp|NOBODY", persistedUser.getSubject());
        assertTrue(persistedUser.isMatched());
        persistedUser = null;
        // Test when no user matches
        userInfo = mockAuthAPIUserInfo("no-user-token");
        result = cut.matchTokenToUser(userInfo);
        assertNull(result);
        // Test when path not found in auth0metadata -- This is a problem with the mapping data in the database
        userInfo = mockAuthAPIUserInfo("invalid-path-token");
        result = cut.matchTokenToUser(userInfo);
        assertNull(result);
        // Test when no mappings in database -- We have no mappings set up for this yet
        userInfo = mockAuthAPIUserInfo("no-mapping-connection-token");
        result = cut.matchTokenToUser(userInfo);
        assertNull(result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : User(edu.harvard.hms.dbmi.avillach.auth.data.entity.User) JsonNode(com.fasterxml.jackson.databind.JsonNode) Auth0Exception(com.auth0.exception.Auth0Exception) IOException(java.io.IOException) Test(org.junit.Test)

Example 13 with UserInfo

use of com.auth0.json.auth.UserInfo in project sirius by boecker-lab.

the class AccountPanel method reloadChanges.

public void reloadChanges() {
    DecodedJWT userInfo = getLogin();
    if (userInfo == null) {
        userIconLabel.setIcon(Icons.USER_128);
        userInfoLabel.setText("Please log in!");
        create.setAction(SiriusActions.SIGN_UP.getInstance());
        login.setAction(SiriusActions.SIGN_IN.getInstance());
        refresh.setEnabled(false);
    } else {
        refresh.setEnabled(true);
        try {
            Image image = ImageIO.read(new URL(userInfo.getClaim("picture").asString()));
            image = Icons.makeEllipse(image);
            image = Icons.scaledInstance(image, 128, 128);
            userIconLabel.setIcon(new ImageIcon(image));
        } catch (Throwable e) {
            LoggerFactory.getLogger(getClass()).warn("Could not load profile image: " + e.getMessage());
            userIconLabel.setIcon(Icons.USER_GREEN_128);
        }
        userInfoLabel.setText("<html>Logged in as:<br><b>" + userInfo.getClaim("email").asString() + "</b>" + "<br>" + "(" + userInfo.getClaim("sub").asString() + ")" + "</html>");
        create.setAction(SiriusActions.DELETE_ACCOUNT.getInstance());
        login.setAction(SiriusActions.SIGN_OUT.getInstance());
    }
}
Also used : DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) URL(java.net.URL)

Aggregations

IOException (java.io.IOException)7 Test (org.junit.Test)7 Algorithm (com.auth0.jwt.algorithms.Algorithm)6 JWT (com.auth0.jwt.JWT)5 Duration (java.time.Duration)5 Instant (java.time.Instant)5 MetadataPage (io.gravitee.common.data.domain.MetadataPage)4 Maps (io.gravitee.common.util.Maps)4 ExpressionEvaluationException (io.gravitee.el.exceptions.ExpressionEvaluationException)4 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)4 MembershipRepository (io.gravitee.repository.management.api.MembershipRepository)4 UserRepository (io.gravitee.repository.management.api.UserRepository)4 ApplicationType (io.gravitee.repository.management.model.ApplicationType)4 Membership (io.gravitee.repository.management.model.Membership)4 User (io.gravitee.repository.management.model.User)4 UserStatus (io.gravitee.repository.management.model.UserStatus)4 io.gravitee.rest.api.model (io.gravitee.rest.api.model)4 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)4 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)4 AuditEntity (io.gravitee.rest.api.model.audit.AuditEntity)4