Easy way to query oidc protected rest api using access token? #25
-
Hi, I'm using this library to authenticate my flutter app against my keycloak instance (https://sso.domain.com) and want to call various rest apis afterwards which are all protected by the same keycloak instance. My guess would have been that there would be an easy way of using this library for: "make a get request using the currently authenticated user" but I can't seem to find any. I then tried to make a http get request using the obtained access token like this but this only redirects me to the keycloak login page:
Any pointers would be appreciated. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
as you guessed, I have no idea how the reason we don't provide an easy way for "make a get request using the currently authenticated user" Internally we even use the access token in the using package:http to send the request: https://github.com/Bdaya-Dev/oidc/blob/main/packages/oidc_core/lib/src/endpoints/facade.dart#L416-L431 |
Beta Was this translation helpful? Give feedback.
-
Thank you for the fast answer! At least I know now that I'm on the right track.. thanks! |
Beta Was this translation helpful? Give feedback.
as you guessed,
user.token.accessToken
gives you the raw access token, but it's up to you how you use it.I have no idea how
restbackend.domain.com
is configured, and how it accepts auth parameters, but it should be as easy as setting'Authorization': 'Bearer ' + token
as you did.the reason we don't provide an easy way for "make a get request using the currently authenticated user"
is because the user might want to use another networking library (e.g.
dio
).Internally we even use the access token in the
/userinfo
request to validate that it actually workssee:
oidc/packages/oidc/lib/src/managers/user_manager.dart
Line 738 in 0d5782d