Hi all,
I am trying to set up a config with a client, hydra+consent and an api. The client gets a token with given scopes from hydra (after user consent), this works. Now I send the token to the api. The api needs to check if the token is active and valid for a certain scope. When using the SDK, this is done with IntrospectOAuth2Token as far as I can tell from the docs. I can’t get this to work and a little help would be great.
I have set up a client for the api with
clients create --skip-tls-verify \
--id protected-api \
--secret $API_SECRET \
--allowed-scopes hydra.clients, hydra.introspect \
--grant-types client_credentials \
--response-types token
and policy:
policies create --skip-tls-verify \
--id check-token-policy \
--description "Allow api to check token with /oauth2/introspect" \
--allow \
--actions introspect \
--resources rn:hydra:oauth2:tokens \
--subjects protected-api
The protected-api initializes the hydra SDK
client, err = hydra.NewSDK(&hydra.Configuration{
ClientID: env.Getenv("CLIENT_ID", "demo"),
ClientSecret: env.Getenv("CLIENT_SECRET", "demo"),
EndpointURL: env.Getenv("HYDRA_URL", "https://hydra:4444"),
Scopes: []string{"hydra.clients"},
})
and then gets the token from the request with the function bearerTokenFromRequest® (copied from oathkeeper) and calls
introspection, response, err := client.IntrospectOAuth2Token(token, "")
When I check the logs, I see that both /oauth2/token and /oauth2/introspect are requested
time="2018-05-09T18:56:29Z" level=info msg="started handling request" method=POST remote="172.18.0.4:56826" request=/oauth2/token
time="2018-05-09T18:56:29Z" level=info msg="completed handling request" measure#https://localhost:9000.latency=80625203 method=POST remote="172.18.0.4:56826" request=/oauth2/token status=200 text_status=OK took=80.625203ms
time="2018-05-09T18:56:29Z" level=info msg="started handling request" method=POST remote="172.18.0.4:56826" request=/oauth2/introspect
time="2018-05-09T18:56:29Z" level=info msg="Access denied" error=invalid_scope reason="Token is expired, malformed or missing" request="&{rn:hydra:oauth2:tokens introspect map[]}" scopes="[hydra.introspect]"
i) Why is /oauth2/token requested before /oauth2/introspect?
ii) Why is access denied? I tried to add the scope “hydra.introspect” to the Scopes parameter in NewSDK(), but then I get the following error.
time="2018-05-09T19:19:01Z" level=info msg="started handling request" method=POST remote="172.18.0.4:57248" request=/oauth2/token
time="2018-05-09T19:19:02Z" level=error msg="An error occurred" debug="The client is not allowed to request scope hydra.introspect" error=invalid_scope
Anyone knows what I am missing? There are 2 posts related to this one, but they directly post to the /oauth2/introspect endpoint. I could try that to get it to work, but I would also like to understand why my approach with the SDK is failing.
Thanx for any help!