From c86a6ba3f3cada8cb64a486ad8cc960688077097 Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Fri, 15 Aug 2014 11:46:38 -0400 Subject: [PATCH 1/3] fix admin reset email --- .../services/resources/admin/UsersResource.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java b/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java index 628ef9a7c4..dd3f1a89d9 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/UsersResource.java @@ -4,6 +4,8 @@ import org.jboss.logging.Logger; import org.jboss.resteasy.annotations.cache.NoCache; import org.jboss.resteasy.spi.BadRequestException; import org.jboss.resteasy.spi.NotFoundException; +import org.keycloak.ClientConnection; +import org.keycloak.audit.Details; import org.keycloak.email.EmailException; import org.keycloak.email.EmailProvider; import org.keycloak.models.ApplicationModel; @@ -72,6 +74,9 @@ public class UsersResource { private TokenManager tokenManager; + @Context + protected ClientConnection clientConnection; + @Context protected UriInfo uriInfo; @@ -828,7 +833,10 @@ public class UsersResource { return Flows.errors().error("AccountProvider management not enabled", Response.Status.INTERNAL_SERVER_ERROR); } - AccessCode accessCode = tokenManager.createAccessCode(scope, state, redirect, session, realm, client, user, null); + UserSessionModel userSession = session.sessions().createUserSession(realm, user, username, clientConnection.getRemoteAddr(), "form", false); + //audit.session(userSession); + + AccessCode accessCode = tokenManager.createAccessCode(null, state, redirect, session, realm, client, user, userSession); accessCode.setRequiredAction(UserModel.RequiredAction.UPDATE_PASSWORD); try { @@ -838,8 +846,9 @@ public class UsersResource { String link = builder.build(realm.getName()).toString(); long expiration = TimeUnit.SECONDS.toMinutes(realm.getAccessCodeLifespanUserAction()); - session.getProvider(EmailProvider.class).setRealm(realm).setUser(user).sendPasswordReset(link, expiration); + this.session.getProvider(EmailProvider.class).setRealm(realm).setUser(user).sendPasswordReset(link, expiration); + //audit.user(user).detail(Details.EMAIL, user.getEmail()).detail(Details.CODE_ID, accessCode.getCodeId()).success(); return Response.ok().build(); } catch (EmailException e) { logger.error("Failed to send password reset email", e); From 8b1483d7ef41e7afddced087c5c4df89cf8af145 Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Mon, 18 Aug 2014 10:48:28 -0400 Subject: [PATCH 2/3] docs --- docbook/reference/en/en-US/modules/social-github.xml | 2 +- .../admin/base/resources/partials/realm-default-roles.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 docbook/reference/en/en-US/modules/social-github.xml diff --git a/docbook/reference/en/en-US/modules/social-github.xml b/docbook/reference/en/en-US/modules/social-github.xml old mode 100644 new mode 100755 index 4315f6db05..1890f87986 --- a/docbook/reference/en/en-US/modules/social-github.xml +++ b/docbook/reference/en/en-US/modules/social-github.xml @@ -1,7 +1,7 @@
GitHub - To enable login with Google you first have to create an application in + To enable login with GitHub you first have to create an application in GitHub Settings. Then you need to copy the client id and secret into the Keycloak Admin Console. diff --git a/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/realm-default-roles.html b/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/realm-default-roles.html index a7d28d3839..a13e54438f 100755 --- a/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/realm-default-roles.html +++ b/forms/common-themes/src/main/resources/theme/admin/base/resources/partials/realm-default-roles.html @@ -6,7 +6,7 @@

-

{{realm.realm}} Default Roles

+

{{realm.realm}} Default Roles

Realm Default Roles From 80904209b34c41c6106dfdaf2e412a5cc8fd7eed Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Mon, 18 Aug 2014 11:55:27 -0400 Subject: [PATCH 3/3] KEYCLOAK-627 --- .../en/en-US/modules/social-facebook.xml | 6 ++++-- .../en/en-US/modules/social-twitter.xml | 2 +- social/facebook/pom.xml | 5 +++++ .../social/facebook/FacebookProvider.java | 16 ++++++++++++++-- 4 files changed, 24 insertions(+), 5 deletions(-) mode change 100644 => 100755 docbook/reference/en/en-US/modules/social-facebook.xml mode change 100644 => 100755 docbook/reference/en/en-US/modules/social-twitter.xml diff --git a/docbook/reference/en/en-US/modules/social-facebook.xml b/docbook/reference/en/en-US/modules/social-facebook.xml old mode 100644 new mode 100755 index 6e5e832db8..ddc25d5390 --- a/docbook/reference/en/en-US/modules/social-facebook.xml +++ b/docbook/reference/en/en-US/modules/social-facebook.xml @@ -18,7 +18,8 @@ - Once the app has been created click on Settings in sidebar on the left. Then click + Once the app has been created click on Settings in sidebar on the left. You must specify + a contact email. Save your changes. Then click on Advanced. Under Security make sure Client OAuth Login is enabled. In Valid OAuth redirect URIs insert the social callback url. Scroll down and click on the @@ -28,7 +29,8 @@ Click Status & Review and select YES for Do you want - to make this app and all its live features available to the general public?. + to make this app and all its live features available to the general public?. You will + not be able to set this until you have provided a contact email in the general settings of this application. diff --git a/docbook/reference/en/en-US/modules/social-twitter.xml b/docbook/reference/en/en-US/modules/social-twitter.xml old mode 100644 new mode 100755 index 66f0d8307b..f6afdc66fb --- a/docbook/reference/en/en-US/modules/social-twitter.xml +++ b/docbook/reference/en/en-US/modules/social-twitter.xml @@ -22,7 +22,7 @@ - Now click Details. Copy Consumer key and Consumer secret from the + Now click API Keys tab. Copy API key and API secret from the Twitter Developer Console into the settings page in the Keycloak Admin Console as the Key and Secret. Then click Save in the Keycloak Admin Console to enable login with Twitter. diff --git a/social/facebook/pom.xml b/social/facebook/pom.xml index 8d55bc00fb..39b076f5e3 100755 --- a/social/facebook/pom.xml +++ b/social/facebook/pom.xml @@ -25,5 +25,10 @@ jackson-mapper-asl provided + + org.jboss.logging + jboss-logging + provided + diff --git a/social/facebook/src/main/java/org/keycloak/social/facebook/FacebookProvider.java b/social/facebook/src/main/java/org/keycloak/social/facebook/FacebookProvider.java index 4f15fbbe2b..f8b5dedb95 100755 --- a/social/facebook/src/main/java/org/keycloak/social/facebook/FacebookProvider.java +++ b/social/facebook/src/main/java/org/keycloak/social/facebook/FacebookProvider.java @@ -1,6 +1,7 @@ package org.keycloak.social.facebook; import org.codehaus.jackson.JsonNode; +import org.jboss.logging.Logger; import org.keycloak.social.AbstractOAuth2Provider; import org.keycloak.social.SocialProviderException; import org.keycloak.social.SocialUser; @@ -10,6 +11,7 @@ import org.keycloak.social.utils.SimpleHttp; * @author Stian Thorgersen */ public class FacebookProvider extends AbstractOAuth2Provider { + protected static final Logger logger = Logger.getLogger(FacebookProvider.class); private static final String ID = "facebook"; private static final String NAME = "Facebook"; @@ -50,10 +52,20 @@ public class FacebookProvider extends AbstractOAuth2Provider { try { JsonNode profile = SimpleHttp.doGet(PROFILE_URL).header("Authorization", "Bearer " + accessToken).asJson(); - SocialUser user = new SocialUser(profile.get("id").getTextValue(), profile.get("username").getTextValue()); + + JsonNode id = profile.get("id"); + JsonNode username = profile.get("username"); + JsonNode email = profile.get("email"); + + //logger.info("email is null: " + email == null); + //logger.info("username is null: " + username == null); + + if (username == null) username = email == null ? id : email; + + SocialUser user = new SocialUser(id.getTextValue(), username.getTextValue()); user.setName(profile.has("first_name") ? profile.get("first_name").getTextValue() : null, profile.has("last_name") ? profile.get("last_name").getTextValue() : null); - user.setEmail(profile.has("email") ? profile.get("email").getTextValue() : null); + user.setEmail(profile.has("email") ? email.getTextValue() : null); return user; } catch (Exception e) {