Skip to content
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

OAuth 2 refresh token support #8175

Open
nelle775 opened this issue Mar 4, 2019 · 9 comments
Open

OAuth 2 refresh token support #8175

nelle775 opened this issue Mar 4, 2019 · 9 comments
Labels
affected-medium This issue impacts approximately half of our customers area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer enhancement This issue represents an ask for new feature or an enhancement to an existing one severity-major This label is used by an internal tool

Comments

@nelle775
Copy link

nelle775 commented Mar 4, 2019

The OAuthHandler class does not provide any option to expire the underlying Cookie ticket upon expiry of the Bearer Token, also it does not have any support for Refresh tokens other than storing the value in AuthenticationProperties.

I Suggest the following:
Add a property: bool ExpireUponTokenExpiry to RemoteAuthenticationOptions

On authenticating ticket, check this property
if false just return AuthenticateResult.Success upon validating the ticket
if true and bearer token is not expired return AuthenticateResult.Success
if true and bearer token is expired
-> if refresh_token isSet in AuthenticationProperties, Exhange the refresh token for new bearer token through http backchannel,
-> if no refresh_token is set, start a new OAuth authentication flow, with RedirectResult

@blowdart blowdart added the area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer label Mar 4, 2019
@Tratcher
Copy link
Member

Tratcher commented Mar 4, 2019

The UseTokenLifetime OIDC option already does part of this, tying the cookie lifetime to the token lifetime, though most people don't like it and have turned it off.

The biggest gap in the suggested design is that RemoteAuth.AuthenticateAsync doesn't run every request, it only runs during sign-in. After sign-in it's CookieAuth.AuthenticateAsync that runs every request and it doesn't know about the upstream details.

The other big gap is that refresh is not a well standardized behavior for OAuth. I tried it with a few of our common providers and only two out of five were able to share any of their logic. This was my last experiment at refresh: https://github.com/aspnet/AspNetCore/blob/39e52578d354a6a7abb3f6169d5ac2174ffe4551/src/Security/Authentication/samples/SocialSample/Startup.cs

We do need to provide better refresh support, but I doubt it would ever be completely automatic. A big reason is concurrency. If you have any parallel requests from the same user they would all start attempting the refresh as soon as the token expired. A better pattern I've seen is to only refresh the token when you go to use it. That cuts down the concurrency as you only use that token on a small subset of requests.

@Eilon Eilon added this to the Backlog milestone Mar 26, 2019
@Eilon
Copy link
Member

Eilon commented Mar 26, 2019

Placing in backlog so we can consider in a future version.

@Tratcher Tratcher added affected-medium This issue impacts approximately half of our customers enhancement This issue represents an ask for new feature or an enhancement to an existing one severity-major This label is used by an internal tool labels Nov 10, 2020 — with ASP.NET Core Issue Ranking
@AdamWyzgol
Copy link

really still in backlog? since 2019?

@halter73 halter73 modified the milestones: Backlog, .NET 10 Planning Sep 27, 2024
@halter73
Copy link
Member

halter73 commented Sep 27, 2024

Moving out of backlog for consideration in .NET 10. We could look at CookieOidcRefresher for inspiration although that's specifically for the OpenIdConnectHandler rather than the OAuthHandler. It would be nice to add refresh support to both.

#55213 is related but even tricker because in the case of Blazor Server interactivity it's harder to store the refreshed tokens in an updated cookie

@Fronix
Copy link

Fronix commented Nov 8, 2024

For anyone who keeps returning here hoping for some type of revelation:

https://github.com/DuendeSoftware/Duende.AccessTokenManagement has created something that seems to work and has working examples...

@josephdecock
Copy link
Contributor

josephdecock commented Nov 8, 2024

Thanks for the shoutout @Fronix! I'm one of the maintainers of Duende.AccessTokenManagement, so I thought I'd chime in. We're an apache licensed library sponsored by Duende Software for automatically managing access tokens.

In addition to simple token management, we also have support for DPoP (sender constrained tokens). And we have an extensibility point for storing tokens outside of cookies (especially helpful for Blazor Server).

@developer9969
Copy link

@josephdecock Hi come across this thread and also used in a pluralsight course I have just watched, my question is , is the accesstokenManagment nuget free to use in commercial application?

@brockallen
Copy link

brockallen commented Dec 16, 2024

Hi come across this thread and also used in a pluralsight course I have just watched, my question is , is the accesstokenManagment nuget free to use in commercial application?

Yes, Apache2.

https://www.nuget.org/packages/Duende.AccessTokenManagement

@alefcarlos
Copy link

Hey, josephdecock, good ? Even if I use Duende.AccessTokenManagement I have to implement CookieRefresh's logic, right ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected-medium This issue impacts approximately half of our customers area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer enhancement This issue represents an ask for new feature or an enhancement to an existing one severity-major This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests