Search code examples
authenticationkeycloakprovider

How to distinguish if user is logged in from a Provider or from a user in Keycloak


I am integrating Keycloak into a React Application. I have successfully added Google Providers in Keycloak. Now the user can either log in with Keycloak user's credentials or from Login with Google. After login how to distinguish if a user is with React or with a Provider? And how to acquire the ID of that user so for certain activities to store that ID in the database?


Solution

  • GET User's detail REST API detect which identity provider's user.

    Get representation of the user

    enter image description here

    The federatedIdentities fields shows it

    enter image description here

    here

    enter image description here

    Demo this user login via google

    You needs a master token in Posman.

    #1 Get master token at Posman.

    Detail instruction here

    #2 Get user list

    GET http://localhost:8080/auth/admin/realms/my-realm/users
    

    #3 Get google user

    GET http://localhost:8080/auth/admin/realms/my-realm/users/{google-user-uuid}
    

    enter image description here

    #4 Get regular user

    GET http://localhost:8080/auth/admin/realms/my-realm/users/{user-uuid}
    

    This user logged via regular Keycloak enter image description here