use of org.keycloak.broker.provider.IdentityBrokerException in project keycloak by keycloak.
the class OpenshiftV4IdentityProviderTest method testHttpClientErrors.
@Test
public void testHttpClientErrors() {
// given
OpenshiftV4IdentityProviderConfig config = new OpenshiftV4IdentityProviderConfig(new IdentityProviderModel());
// when
try {
new OpenshiftV4IdentityProvider(null, config) {
@Override
InputStream getOauthMetadataInputStream(KeycloakSession session, String baseUrl) {
throw new RuntimeException("Failed : HTTP error code : 500");
}
};
Assert.fail();
} catch (IdentityBrokerException e) {
// then
// OK
}
}
use of org.keycloak.broker.provider.IdentityBrokerException in project keycloak by keycloak.
the class OpenshiftV4IdentityProvider method getAuthJson.
Map<String, Object> getAuthJson(KeycloakSession session, String baseUrl) {
try {
InputStream response = getOauthMetadataInputStream(session, baseUrl);
Map<String, Object> map = mapMetadata(response);
return map;
} catch (Exception e) {
throw new IdentityBrokerException("Could not initialize oAuth metadata", e);
}
}
use of org.keycloak.broker.provider.IdentityBrokerException 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.IdentityBrokerException in project keycloak by keycloak.
the class FacebookIdentityProvider method doGetFederatedIdentity.
protected BrokeredIdentityContext doGetFederatedIdentity(String accessToken) {
try {
final String fetchedFields = getConfig().getFetchedFields();
final String url = StringUtil.isNotNull(fetchedFields) ? String.join(PROFILE_URL_FIELDS_SEPARATOR, PROFILE_URL, fetchedFields) : PROFILE_URL;
JsonNode profile = SimpleHttp.doGet(url, session).header("Authorization", "Bearer " + accessToken).asJson();
return extractIdentityFromProfile(null, profile);
} catch (Exception e) {
throw new IdentityBrokerException("Could not obtain user profile from facebook.", e);
}
}
use of org.keycloak.broker.provider.IdentityBrokerException in project keycloak by keycloak.
the class GitHubIdentityProvider method searchEmail.
private String searchEmail(String accessToken) {
try {
ArrayNode emails = (ArrayNode) SimpleHttp.doGet(EMAIL_URL, session).header("Authorization", "Bearer " + accessToken).asJson();
Iterator<JsonNode> loop = emails.elements();
while (loop.hasNext()) {
JsonNode mail = loop.next();
if (mail.get("primary").asBoolean()) {
return getJsonProperty(mail, "email");
}
}
} catch (Exception e) {
throw new IdentityBrokerException("Could not obtain user email from github.", e);
}
throw new IdentityBrokerException("Primary email from github is not found.");
}
Aggregations