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

Token authentication updates #31214

Merged
merged 7 commits into from
Dec 8, 2023
Merged

Token authentication updates #31214

merged 7 commits into from
Dec 8, 2023

Conversation

guardrex
Copy link
Collaborator

@guardrex guardrex commented Dec 7, 2023

Fixes #31194

Thanks @SandroRiz.

Stephen, Jeremy ... These changes take into account that the dev will need to write custom code. I have a feeling that this is going to generate doc issues from devs asking for a complete implementation. I presume that you want me to tell them that we're not going to support it in our docs and that they should research it on the Net and use public support channels for assistance.

Also, @halter73 ... You didn't mention in your PU issue remarks the piece on AddBearerToken. I left that in the section, so let me know if it gets the 🔪 chop ... or a change to something else.

UPDATE: I see what you and Tom did in the main article. That's better, but it still isn't a complete, fully working implementation. The text over there is below. I'll make cross-link to that article because there's other scenarios there that should be surfaced, too.

If useCookies is false or omitted, token-based authentication is enabled. The response body includes the following properties:

{
  "tokenType": "string",
  "accessToken": "string",
  "expiresIn": 0,
  "refreshToken": "string"
}

For more information about these properties, see xref:Microsoft.AspNetCore.Authentication.BearerToken.AccessTokenResponse.
Put the access token in a header to make authenticated requests, as shown in the following example

Authorization: Bearer {access token}

When the access token is about to expire, call the /refresh endpoint.

Use the POST /refresh endpoint

For use only with token-based authentication. Gets a new access token without forcing the user to log in again. Call this endpoint when the access token is about to expire.
The request body contains only the xref:Microsoft.AspNetCore.Identity.Data.RefreshRequest.RefreshToken. Here's a request body example:

{
  "refreshToken": "string"
}

If the call is successful, the response body is a new xref:Microsoft.AspNetCore.Authentication.BearerToken.AccessTokenResponse, as shown in the following example:

{
  "tokenType": "string",
  "accessToken": "string",
  "expiresIn": 0,
  "refreshToken": "string"
}

Internal previews

📄 File 🔗 Preview link
aspnetcore/blazor/security/webassembly/standalone-with-identity.md Secure ASP.NET Core Blazor WebAssembly with ASP.NET Core Identity

@guardrex guardrex self-assigned this Dec 7, 2023
Copy link
Member

@JeremyLikness JeremyLikness left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Made one simple suggestion.

@guardrex guardrex merged commit aea7d7a into main Dec 8, 2023
3 checks passed
@guardrex guardrex deleted the guardrex-patch-3 branch December 8, 2023 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update token auth guidance
3 participants