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

Authentication revalidation for server-side Blazor #10698

Closed
mkArtakMSFT opened this issue May 31, 2019 · 7 comments
Closed

Authentication revalidation for server-side Blazor #10698

mkArtakMSFT opened this issue May 31, 2019 · 7 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components Done This issue has been fixed enhancement This issue represents an ask for new feature or an enhancement to an existing one

Comments

@mkArtakMSFT
Copy link
Member

mkArtakMSFT commented May 31, 2019

No description provided.

@mkArtakMSFT mkArtakMSFT added enhancement This issue represents an ask for new feature or an enhancement to an existing one PRI: 1 - Required area-blazor Includes: Blazor, Razor Components labels May 31, 2019
@mkArtakMSFT mkArtakMSFT added this to the 3.0.0-preview7 milestone May 31, 2019
@mkArtakMSFT
Copy link
Member Author

Moving the client-side work out to: #10846

@danroth27 danroth27 changed the title Finalize Auth work in Blazor Authentication revalidation for server-side Blazor Jun 5, 2019
SteveSandersonMS added a commit that referenced this issue Jun 28, 2019
@SteveSandersonMS SteveSandersonMS added Done This issue has been fixed and removed Working labels Jun 28, 2019
@SteveSandersonMS
Copy link
Member

Done in #11548

@Yen
Copy link

Yen commented Jul 24, 2019

Please let me know if I am wrong, but #11548 does not solve this issue for authentication, it solves it for identity based authorization.

We are currently using cookie authentication with microsoft AD to validate logins to internal applications where we do not require associated data from a db with identity. For the traditional MVC style system we would set CookieAuthenticationOptions.ExpireTimeSpan and be done with it, but how would we go about expiring a server side blazor session in a secure way outside of rolling our own hacks?

What we are currently using is a check in OnGet to see if the user is authenticated followed by a redirect to a login razor page from the _Host.cshtml file. This is fine for stopping people from loading any of the blazor pages using _Host as the root, but does nothing to stop an existing connection from being used.

Is there any way this system can be used with authentication without identity as we do not want an entity framework store of any sort where not required, and if not, are there plans to have this scenario supported?

@ADefWebserver
Copy link

@Yen
Copy link

Yen commented Jul 24, 2019

@ADefWebserver Thank you for your reference but I don't believe this is what I am looking for. I am sure it is possible to check for the authentication state by manually looking at the expiration dates of the cookies as they are given during the creation of the websocket instance. However this is not a complete solution, nor do I believe it is a response to this issue. In this case we are looking for a way to revalidate authentication on the existing websocket connection, without the requirement to validate each function call made from the blazor component.

@SteveSandersonMS
Copy link
Member

@Yen You're correct that the built-in system only addresses the scenario for identity-based authentication. It periodically checks whether the user's security stamp has changed, and if so, invalidates their current authentication state (which in turn causes authorization rules to be re-evaluated).

We don't have, and aren't planning to have in 3.0, and general system for reauthenticating across all possible authentication types. The reason is that there isn't a general way to do it. For example, we don't have a way of asking the cookie authentication system to re-check the possible expiry of tokens encoded into a cookie.

For now, if this is required in your app, consider implementing a custom AuthenticationStateProvider that uses whatever logic you want to recheck authentication state, similar to how we did it for identity.

Longer term we hope to add a more general feature to SignalR to enable rechecking of authentication state, but it won't be in 3.0. cc @anurse

@Yen
Copy link

Yen commented Jul 24, 2019

@SteveSandersonMS Thanks for the response Steve, it is a shame that your support for this is limited to those using Identity but understandable.

I wanted to add, for anyone else having the same issue, that to solve my issue I have decided to make a custom AuthenticationStateProvider that uses HttpContext.AuthenticateAsync with the cookie authentication scheme to get an AuthenticateResult. This then gives me access to IssuedUtc and ExpiresUtc, which is all the information needed to perform the check and invalidate the connection. (In my case I am ignoring the ExpiresUtc and using the current CookieAuthenticationOptions.ExpireTimeSpan for the calculation so that changes in the expiration duration cross session is considered.)

I don't know if this is enough to classify for your "we don't have a way of asking the cookie authentication system to re-check the possible expiry of tokens encoded into a cookie.", or if you are looking for something else I have missed. :)

@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components Done This issue has been fixed enhancement This issue represents an ask for new feature or an enhancement to an existing one
Projects
None yet
Development

No branches or pull requests

4 participants