use of org.keycloak.broker.provider.BrokeredIdentityContext in project keycloak by keycloak.
the class StackoverflowIdentityProvider method extractIdentityFromProfile.
@Override
protected BrokeredIdentityContext extractIdentityFromProfile(EventBuilder event, JsonNode node) {
JsonNode profile = node.get("items").get(0);
BrokeredIdentityContext user = new BrokeredIdentityContext(getJsonProperty(profile, "user_id"));
String username = extractUsernameFromProfileURL(getJsonProperty(profile, "link"));
user.setUsername(username);
user.setName(unescapeHtml3(getJsonProperty(profile, "display_name")));
// email is not provided
// user.setEmail(getJsonProperty(profile, "email"));
user.setIdpConfig(getConfig());
user.setIdp(this);
AbstractJsonUserAttributeMapper.storeUserProfileForMapper(user, profile, getConfig().getAlias());
return user;
}
use of org.keycloak.broker.provider.BrokeredIdentityContext in project keycloak by keycloak.
the class GitLabIdentityProvider method gitlabExtractFromProfile.
private BrokeredIdentityContext gitlabExtractFromProfile(JsonNode profile) {
String id = getJsonProperty(profile, "id");
BrokeredIdentityContext identity = new BrokeredIdentityContext(id);
String name = getJsonProperty(profile, "name");
String preferredUsername = getJsonProperty(profile, "username");
String email = getJsonProperty(profile, "email");
AbstractJsonUserAttributeMapper.storeUserProfileForMapper(identity, profile, getConfig().getAlias());
identity.setId(id);
identity.setName(name);
identity.setEmail(email);
identity.setBrokerUserId(getConfig().getAlias() + "." + id);
if (preferredUsername == null) {
preferredUsername = email;
}
if (preferredUsername == null) {
preferredUsername = id;
}
identity.setUsername(preferredUsername);
return identity;
}
use of org.keycloak.broker.provider.BrokeredIdentityContext in project keycloak by keycloak.
the class InstagramIdentityProvider method doGetFederatedIdentity.
protected BrokeredIdentityContext doGetFederatedIdentity(String accessToken) {
try {
// try to get the profile incl. legacy Instagram ID to allow existing users to log in
JsonNode profile = fetchUserProfile(accessToken, true);
// ig_id field will get deprecated in the future and eventually might stop working (returning error)
if (!profile.has("id")) {
logger.debugf("Could not fetch user profile from instagram. Trying without %s.", LEGACY_ID_FIELD);
profile = fetchUserProfile(accessToken, false);
}
logger.debug(profile.toString());
// it's not documented whether the new ID system can or cannot have conflicts with the legacy system, therefore
// we're using a custom prefix just to be sure
String id = "graph_" + getJsonProperty(profile, "id");
String username = getJsonProperty(profile, "username");
String legacyId = getJsonProperty(profile, LEGACY_ID_FIELD);
BrokeredIdentityContext user = new BrokeredIdentityContext(id);
user.setUsername(username);
user.setIdpConfig(getConfig());
user.setIdp(this);
if (legacyId != null && !legacyId.isEmpty()) {
user.setLegacyId(legacyId);
}
AbstractJsonUserAttributeMapper.storeUserProfileForMapper(user, profile, getConfig().getAlias());
return user;
} catch (Exception e) {
throw new IdentityBrokerException("Could not obtain user profile from instagram.", e);
}
}
use of org.keycloak.broker.provider.BrokeredIdentityContext in project keycloak by keycloak.
the class MicrosoftIdentityProvider method extractIdentityFromProfile.
@Override
protected BrokeredIdentityContext extractIdentityFromProfile(EventBuilder event, JsonNode profile) {
String id = getJsonProperty(profile, "id");
BrokeredIdentityContext user = new BrokeredIdentityContext(id);
String email = getJsonProperty(profile, "mail");
if (email == null && profile.has("userPrincipalName")) {
String username = getJsonProperty(profile, "userPrincipalName");
if (Validation.isEmailValid(username)) {
email = username;
}
}
user.setUsername(email != null ? email : id);
user.setFirstName(getJsonProperty(profile, "givenName"));
user.setLastName(getJsonProperty(profile, "surname"));
if (email != null)
user.setEmail(email);
user.setIdpConfig(getConfig());
user.setIdp(this);
AbstractJsonUserAttributeMapper.storeUserProfileForMapper(user, profile, getConfig().getAlias());
return user;
}
use of org.keycloak.broker.provider.BrokeredIdentityContext in project keycloak by keycloak.
the class BitbucketIdentityProvider method extractUserInfo.
private BrokeredIdentityContext extractUserInfo(String subjectToken, JsonNode profile) {
BrokeredIdentityContext user = new BrokeredIdentityContext(getJsonProperty(profile, "account_id"));
String username = getJsonProperty(profile, "username");
user.setUsername(username);
user.setName(getJsonProperty(profile, "display_name"));
user.setIdpConfig(getConfig());
user.setIdp(this);
AbstractJsonUserAttributeMapper.storeUserProfileForMapper(user, profile, getConfig().getAlias());
try {
JsonNode emails = SimpleHttp.doGet(USER_EMAIL_URL, session).header("Authorization", "Bearer " + subjectToken).asJson();
// {"pagelen":10,"values":[{"is_primary":true,"is_confirmed":true,"type":"email","email":"bburke@redhat.com","links":{"self":{"href":"https://api.bitbucket.org/2.0/user/emails/bburke@redhat.com"}}}],"page":1,"size":1}
JsonNode emailJson = emails.get("values");
if (emailJson != null) {
if (emailJson.isArray()) {
emailJson = emailJson.get(0);
}
if (emailJson != null && "email".equals(getJsonProperty(emailJson, "type"))) {
user.setEmail(getJsonProperty(emailJson, "email"));
}
}
} catch (Exception ignore) {
logger.debug("failed to get email from BitBucket", ignore);
}
return user;
}
Aggregations