How To Signin To Keycloak Using Google

There are iii gear upwards of steps that nosotros must follow inward social club to come upwards up amongst a spider web projection that volition let us to login using google's identity provider.

Set i - Create a google application

  1. Create a google application at https://console.developers.google.com
  2. Set OAuth consent screen
  3. Fill upwards the requirement to exercise a customer id
  4. Save the customer id too secret, nosotros volition utilisation it subsequently when creating a customer inward keycloak

Set ii - Setup Keycloak

  1.  Create realm social-oauth
  2.  Create Identity Provider
    1.     Identity Provider
    2.     Add provider
    3.     Google
  3. Copy the customer id too hush-hush that nosotros salve before inward their respective fields
  4. Create a novel keycloak application client
    1. While inward the client, click the Installation tab
    2. Under format selection choose "Keycloak OIDC JSON"
    3. Copy too glue this value inward a file named keycloak.json within your javaee7 spider web project's web-inf directory.

Set iii - Create our spider web project

  1. Create a novel maven projection using javaee7 blank archetype, cite it social-oauth-demo.
  2. Create a file cite keycloak.json, content volition live on coming from the keycloak customer that nosotros only created.
    It should await similar this:
    {   "realm": "social-auth",   "auth-server-url": "http://localhost:8180/auth",   "ssl-required": "external",   "resource": "social-auth-client",   "public-client": truthful }
  3. Create web.xml file, where nosotros volition specify keycloak every bit the authentication method. Also secure a spider web resource.
    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"  version="3.0">    <module-name>social-auth-demo</module-name>    <security-constraint>   <web-resource-collection>    <web-resource-name>All Pages</web-resource-name>    <url-pattern>/social/*</url-pattern>   </web-resource-collection>   <auth-constraint>    <role-name>social-access</role-name>   </auth-constraint>  </security-constraint>    <login-config>   <auth-method>KEYCLOAK</auth-method>   <realm-name>social-auth</realm-name>  </login-config>  <security-role>   <role-name>social-access</role-name>  </security-role>  </web-app>
  4. Build too deploy the nation of war inward wildfly. Make certain that wildfly has keycloak customer installed.
  5. Open a browser too larn into http://localhost:8080/social-auth-demo/social/index.html, this should redirect to keycloak's login page. You should run across a google icon to login.
The same logic applies to facebook.
Next
Previous
Click here for Comments

0 komentar:

Please comment if there are any that need to be asked.