oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Question: security provider Bearer Token

Open jxsl13 opened this issue 2 years ago • 3 comments

Could someone explain to me how the bearer token security provider is supposed to work if the token expires after 5 minutes?

My understanding would be that the security provider should be passend a token url and depending on the grant_type, either a client_id and client_secret (which is used in case your token expired to fetch a new one in case no refresh_token is used) or for password grant type a username, password and a client_id (some public client w/o secret).

(coming from Keycloak)

jxsl13 avatar May 18 '22 23:05 jxsl13

You should be able to configure Keycloak to grant longer session tokens.

Your frontend application needs to deal with token expiration, because all it does is present the token to the API. The client ID and Client Secret are used by the API to prove its identity to the identity provider, and are required for login flows such as "authorization code". Other flows don't require those, such as implicit flow. Anyhow, your app needs to stay on top of keeping its token fresh, so it's better just to make longer ones, unless your session is extremely sensitive.

I'm not entirely sure of what you're asking.

deepmap-marcinr avatar May 19 '22 07:05 deepmap-marcinr

My question targets the usage of the security provider (of this module) for bearer tokens. Do you create a security provider for every new jwt? as the constructor of the security provider expects a jwt that will seemingly expire in 5 minutes?

jxsl13 avatar May 19 '22 09:05 jxsl13

I'd recommend creating a new type which, instead of hardcoding the token in the security provider, it would perform validation of the JWT in the Intercept method, then it can be dynamic 👍

jamietanna avatar Jun 29 '22 15:06 jamietanna