Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to exchange for google access token. Err: identity provider is not linked #3

Open
stmsevanya opened this issue Sep 1, 2024 · 2 comments

Comments

@stmsevanya
Copy link

stmsevanya commented Sep 1, 2024

I cloned the repo. Started the server on localhost. Imported the realm. Created a user in Users. Generated new client id and secret for Keycloak. Added new client id and secret for google from my google console. Got the access token from keycloak with the step shown in https://youtu.be/LMiS9OYBooI?t=932 . After getting access_token, I tried exchanging it for google access token, but get the error from postman as follows:
Response:
{
"error_description": "identity provider is not linked",
"account-link-url": "http://localhost:8080/realms/czetsuyatech/broker/google/link?nonce=754af160-297a-4f9a-a5c7-4433323b409b&hash=vN9n9xo6UwZ4gz6p010XIgO186lHZNQO-0Q6MX5EJZc&client_id=web-front",
"error": "not_linked"
}

My postman request was this:
curl --location 'http://localhost:8080/realms/czetsuyatech/protocol/openid-connect/token'
--header 'Accept: application/json'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'client_id=web-front'
--data-urlencode 'client_secret=wctUSTlUEJvDfSKW0FJXlYqJ124oArDF'
--data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange'
--data-urlencode 'requested_token_type=urn:ietf:params:oauth:token-type:access_token'
--data-urlencode 'requested_issuer=google'
--data-urlencode 'subject_token=eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJNTnR3MHdwNi03NXZrdXEwbWpkaDN0eXhmQnpFYTQzTUNkSktJMVdlUWcwIn0.eyJleHAiOjE3MjUxODQyNTgsImlhdCI6MTcyNTE4MjQ1OCwiYXV0aF90aW1lIjoxNzI1MTEwNTA0LCJqdGkiOiI1MDMzYmZmYi0zYTRkLTRkY2MtYWFmYS0wNGVlOGFlOWIzOGYiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAv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Qn6zV-hgbCdjs5qELnWnaEO4H2YV4JNxYfsPbOqOuSiWgQ_XTIovIrUpWp9sXczP_N8P3MUuNKQ'
--data-urlencode 'subject_token_type=urn:ietf:params:oauth:token-type:access_token'

From docker logs I see following error/warning:
[org.keycloak.events] (executor-thread-122) type=TOKEN_EXCHANGE_ERROR, realmId=1bfbd22e-5514-407e-9482-c1d4dc7c2646, clientId=web-front, userId=null, ipAddress=192.168.65.1, error=invalid_token, reason='requested_issuer is not linked', auth_method=token_exchange, grant_type=urn:ietf:params:oauth:grant-type:token-exchange, requested_issuer=google, client_auth_method=client-secret

Any idea what I am missing?

@stmsevanya
Copy link
Author

Able to bypass this error when I select SignInWith Google instead of just SignIn.

Wondering is there anyway, to get access token for account which can not be google linked. Let say if I want to sign in Keycloak with my icloud.com account and want to perform google-token-exchange for that so I can get google access token for that icloud account

@czetsuya
Copy link
Collaborator

czetsuya commented Sep 2, 2024

Hi @stmsevanya I don't think it's supported by the current release: https://www.keycloak.org/docs/25.0.2/securing_apps/#_token-exchange.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants