Closed jeluard closed 4 years ago
What kind of validation are you trying to do? I expect the answer to be pretty specific to the API that provides the access_token
, so this may be better asked there (or it may be in their documentation).
I am using github OAuth as a mean of user identification. Once they're logged and I have access to the token, I'd like to use this to validate others endpoint.
I know how to validate a github token but I am wondering if there is a some specific workflow in rocket_oauth2
to handle this lifecycle? (token refresh, invalidation if expired, ..)
Although the TokenResponse
includes the refresh_token
and expires_in
values if the authorization server provided them, I would consider actually using the values as out of scope for rocket_oauth2
. Since the only sure way to validate an access token is to attempt to use it, rocket_oauth2
would need to have a validation mechanism for every provider in order for this to actually work.
rocket_oauth2
does provide a convenient way to make that refresh request, at least: https://docs.rs/rocket_oauth2/0.3.0/rocket_oauth2/struct.OAuth2.html#method.refresh
Thanks!
@jebrosen To check a Github token both client_id
and client_secret
are needed. Is there a way to get this from OAuth2
in an arbitrary endpoint?
@jeluard It can't be accessed via OAuth2
, but I would be happy to accept a PR for that.
There is also https://docs.rs/rocket_oauth2/0.3.1/rocket_oauth2/struct.OAuthConfig.html#method.from_config, which can be used once at startup to read the configuration in the same way OAuth2::fairing()
does. That would allow you to store the client_id
and client_secret
in managed state somewhere.
(Sorry, this is more a question than an issue).
Thanks for your work! Pretty useful :)
What would be a recommended approach to validate the
access_token
in api calls?