-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Research access and refresh tokens behaviours #109918
Comments
Pinging @elastic/kibana-alerting-services (Team:Alerting Services) |
FindingsOAuth Authorization Code FlowFor this flow, we need the user to configure the Oauth provider to provide user consent in order to obtain a valid access token. This access token is short-lived and usually expires in about a day. In order to obtain a new access token, the user either needs to go through the above flow again, or we need to request an additional permission from the user: The refresh token is longer lived, defaults to 90 days, but can expire due to inactivity (depends on how the user has configured their Microsoft service - see previous link). If the refresh token expires, the user will need to go through the initial flow again to obtain a valid access token. (It's worth noting that it seems the ability to configure the duration of the refresh token has recently been removed) Client credentials flow (Graph API)For this flow, we need the user to configure the Oauth provider to provide admin consent in order to obtain a valid access token. This access token is short-lived and usually expires in about a day. In order to obtain a new access token, we just need to call the same Microsoft API with the already provided oauth provider details. We can keep requesting new access tokens indefinitely until the admin consent is revoked. At this point, the user will need to re-consent for us to obtain a new, valid access token. Consent simply involves the user visiting a url like If we attempt to obtain an access token and consent is not provided, we see an error like:
If consent was provided and we obtained a valid access token, but later that consent was revoked, the existing access token will continue to work, but when we request a new one, we will see the same error as above. Questions
Yes, in both flows, the access token is still valid until the
Once an access token expires, Microsoft will return a specific kind of error that we can detect and then request a new access token. Unfortunately, the PoC isn't fleshed out far enough to see where our logic might live to refresh the access token, but I imagine it'd simply live in the email connector
Yup! Like mentioned above, we receive an
I did not find anything in the documentation, nor did I encounter an issue while testing. My testing code
It does, as every time you request a new access token, it will return a new refresh token. It's worth noting that previously created refresh tokens still work as well (they aren't invalidated when a new refresh token is generated). You can control control refresh token duration through the Microsoft admin portal
Like in my testing code above, I didn't encounter any limit when using refresh tokens. I was able to use the original refresh token over and over, as well as using any of the previously returned refresh tokens. |
Can this be closed now that the research has concluded? 🤔 |
Yes! |
We should leverage the authorization code flow POC (#107446) to research and understand what happens to access tokens after we refresh them. Do previous access tokens still work?
With the same POC, we should research how we plan to detect when an access token is expired. This logic will help us understand when to refresh an access token. Is there a way to know how soon it will expire? Are there rate limits to how frequently we can refresh a token?
We should also research if Microsoft Exchange supports refresh token rotation. If so, how many times can a refresh token be rotated?
The text was updated successfully, but these errors were encountered: