Comments (7)
-
You don't have to do all that for server side Blazor, authentication there works the same way it would work for an Mvc or razor pages app. You just add your authentication in startup and decorate your pages with
Authorize
-
This code sample uses aspnet identity, which uses cookies to store the login info. The cookies then are automatically included in http requests to the server. The server authentication middleware checks the cookies to see if you are authenticated or not.
from blazorwithidentity.
but Blazor doesn't allow for the use of cookies... Microsoft also officially says to use plain Razor page instead of Blazor for login. How do you return the cookie via Blazor?
from blazorwithidentity.
Blazor Server supports the same authentication as mvc/razor pages. It supports identity/cookies out of the box, I have done it in production. Sure, you may need a controller or a razor page to create the cookie, but it works. Everything is running on the server and it is using the same authentication/authorization middlewares.
In a production project we have @attribute [Authorize]
in the _Host.razor
page and a different razor page for login. So the whole blazor app is behind authorization, and ofc you can also add @attribute [Authorize(Role = "Admin"]
to blazor pages that you want to use roles/policies and stuff.
from blazorwithidentity.
In production you have a Razor login page, yes that's how it's normally done.
But in this project, the login is a Blazor page, so how does it set the cookie? AFAIK the only way to set cookies is via JS interop... unless Blazor WebAssembly works differently.
from blazorwithidentity.
Login from blazor calls the AuthorizeController
, Login
method that calls await _signInManager.SignInAsync(user, parameters.RememberMe);
which actually writes a set-cookie
header in the response. Then the browser automatically sees this header in the response and creates the cookie.
from blazorwithidentity.
Really? So what I'm getting is that WebAssembly supports cookie creation but not Blazor Server unless using JS interop. Thanks!
from blazorwithidentity.
@mysteryx93 I have implemented it. for server side blazor application base on cookie authentication.
you can refer to https://github.com/neozhu/CleanArchitectureWithBlazorServer
from blazorwithidentity.
Related Issues (20)
- Will there be a similar implementation of authentication by Identity Server? HOT 1
- User.Identity.IsAuthenticated false although SignIn Succeeded HOT 1
- Client Can't login.
- Latest version HOT 2
- How is HttpClient authenticated. There is no access token or code passed when adding the httpclient to services DI HOT 3
- Add validation in login/register form
- Start the BlazorWithIdentity.Client exception separately
- Simple CRUD? HOT 2
- Project Future HOT 2
- Using Sql Server as the Database HOT 2
- How did you deploy this application to Azure?
- Role-based authorization
- Will not get user details for user already logged in HOT 3
- Security Question
- IsLoggedIn issue HOT 4
- Moving Models folder from Server to Shared Project HOT 1
- AuthorizeController.Login returns a stale UserInfo HOT 2
- PW Reset HOT 3
- iOS Device Loading Issue HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blazorwithidentity.