KEYCLOAK-627
This commit is contained in:
parent
8b1483d7ef
commit
80904209b3
4 changed files with 24 additions and 5 deletions
6
docbook/reference/en/en-US/modules/social-facebook.xml
Normal file → Executable file
6
docbook/reference/en/en-US/modules/social-facebook.xml
Normal file → Executable file
|
@ -18,7 +18,8 @@
|
|||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
Once the app has been created click on <literal>Settings</literal> in sidebar on the left. Then click
|
||||
Once the app has been created click on <literal>Settings</literal> in sidebar on the left. You must specify
|
||||
a contact email. Save your changes. Then click
|
||||
on <literal>Advanced</literal>. Under <literal>Security</literal> make sure
|
||||
<literal>Client OAuth Login</literal> is enabled. In <literal>Valid OAuth redirect URIs</literal> insert
|
||||
the <link linkend="social-callbackurl">social callback url</link>. Scroll down and click on the
|
||||
|
@ -28,7 +29,8 @@
|
|||
<listitem>
|
||||
<para>
|
||||
Click <literal>Status & Review</literal> and select <literal>YES</literal> for <literal>Do you want
|
||||
to make this app and all its live features available to the general public?</literal>.
|
||||
to make this app and all its live features available to the general public?</literal>. You will
|
||||
not be able to set this until you have provided a contact email in the general settings of this application.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
|
|
2
docbook/reference/en/en-US/modules/social-twitter.xml
Normal file → Executable file
2
docbook/reference/en/en-US/modules/social-twitter.xml
Normal file → Executable file
|
@ -22,7 +22,7 @@
|
|||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
Now click <literal>Details</literal>. Copy <literal>Consumer key</literal> and <literal>Consumer secret</literal> from the
|
||||
Now click <literal>API Keys</literal> tab. Copy <literal>API key</literal> and <literal>API secret</literal> from the
|
||||
<ulink url="https://dev.twitter.com/apps">Twitter Developer Console</ulink> into the settings
|
||||
page in the Keycloak Admin Console as the <literal>Key</literal> and <literal>Secret</literal>. Then click
|
||||
<literal>Save</literal> in the Keycloak Admin Console to enable login with Twitter.
|
||||
|
|
|
@ -25,5 +25,10 @@
|
|||
<artifactId>jackson-mapper-asl</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.logging</groupId>
|
||||
<artifactId>jboss-logging</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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 <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue