Giter Club home page Giter Club logo

Comments (7)

stavroskasidis avatar stavroskasidis commented on May 22, 2024 1
  1. 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

  2. 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.

mysteryx93 avatar mysteryx93 commented on May 22, 2024

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.

stavroskasidis avatar stavroskasidis commented on May 22, 2024

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.

mysteryx93 avatar mysteryx93 commented on May 22, 2024

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.

stavroskasidis avatar stavroskasidis commented on May 22, 2024

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.

mysteryx93 avatar mysteryx93 commented on May 22, 2024

Really? So what I'm getting is that WebAssembly supports cookie creation but not Blazor Server unless using JS interop. Thanks!

from blazorwithidentity.

neozhu avatar neozhu commented on May 22, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.