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