How to use identity providers in keycloak's REST API?

Viewed 807

I am currently switching from my own "put-together" authentication system to keycloak. I currently hit a bit of a struggle trying to figure out how to use identity providers to login with keycloak. So far, I was able to easily add identity provider's using the rest API: http://localhost:8080/auth/admin/realms/test/users

{"firstName":"FIRSTNAME","lastName":"LASTNAME", "enabled":"true", "username":"app-user", "federatedIdentities": [{"identityProvider": "google", "userId": "XXXXXXXXXXXXXX", "userName": "XXXX XXXXXXXXXXXX"}]}

And after going to the admin panel and logging in through their web interface everything seems to work.

I am currently trying to use the REST API to login but I keep getting the following error

{
    "error": "invalid_grant",
    "error_description": "Code not valid"
}

using the following URL and parameteres

http://localhost:8080/auth/realms/test/protocol/openid-connect/token
clinet_id=test
grant_type=authorization_code
code=XXXX(pulled from frontend using react-social-login)
redirect_uri=http://localhost:8080/redirect
client_secret=XXXXXX

Any help would be appreciated as I would like to be able to complete all login's using the REST API, if you also recommend switching to something that suits my application best (passing information from the frontend and authorizing it in the backend) please let me know.

0 Answers
Related