Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Access Denied with Bearer Token #38

Open
dome4 opened this issue Dec 21, 2019 · 3 comments
Open

Access Denied with Bearer Token #38

dome4 opened this issue Dec 21, 2019 · 3 comments

Comments

@dome4
Copy link
Contributor

dome4 commented Dec 21, 2019

Describe the bug
I created the two clients as described in the documentation. Nevertheless, access to the GraphQL API is denied. I have debugged the connector and found out that the access token of the client in the connector is not validated and therefore access is denied (kauth = {}). Is keycloak-connect suitable for a bearer only api? The two articles on Stackoverflow do not read like this:

To Reproduce
Steps to reproduce the behavior:

  1. Create clients as described in docu

Expected behavior
The access token of the frontend_app can be used to access the graphql api.

Desktop (please complete the following information):

  • OS: Ubuntu 16.04
  • Browser: Firefox
  • Version: 71.0

Setup

  • Keycloak Server: 7.0.0
  • Hasura: 1.0.0
@0xHexE
Copy link
Owner

0xHexE commented Dec 26, 2019

Mostly issue is with keycloak url
If you specify the keycloak url as localhost it will not work instead use ip of the keycloak docker container ip or hostname.

@AdamFerguson
Copy link

In case anyone else runs into this, I had the same problem and it was indeed b/c of the URL's. I was running keycloak, hasura, and the connector in minikube and port forwarding to the containers so I could access locally. The hasura connector would fail running in the cluster but it validated the token when I ran the hasura-connector locally as a node process. It turns out the keycloak connect middleware compares the URL of the keycloak server in the parsed token and the keycloak URL that is configured for the connector. If they don't match, it declares the token invalid. B/C the token was being issued by a port-forwarded keycloak, the token had the url http://localhost:8080/ but I was trying to point the connector at the dns entry for keycloak in the cluster http://keycloak-http.default.svc.cluster.local. Long story short, make sure the URL's are all lined up. Port forwarding can throw it off.

    } else if (token.content.iss !== this.realmUrl) {
      reject(new Error('invalid token (wrong ISS)'));
    } 

@jtiagodev
Copy link

@AdamFerguson Thanks for the feedback...
I'm getting "X-Hasura-Role": "anonymous" when testing the port forwarded service.
But i'm getting the expected body response if i run the service locally (and test against a valid token).

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

No branches or pull requests

4 participants