Blazor with Auth0 Authentication
An update on my Blazor portfolio! I've learned to add authentication using Auth0 which allows me to log in and add add things, while hiding the Add and Edit page and not allowing people to delete my posts willy-nilly. I used this tutorial, which was really pretty simple. The biggest difference in my code was that I wanted to have some API calls be public facing while others were hidden behind authorization. This meant I needed to create two different ProjectApiServices to handle my API calls, one of them added the HttpMessageHandler to authorize certain API calls (starting at line 15).
Once that was done, I just had all the calls I wanted to be private call my AuthenticatedProjectApiService, and then anyone who didn't log in would get a 401 error! Neat! However, it looks nicer when a user who can't use a button doesn't see the button at all. That was simple, I just hid these buttons behind an Authorization tag in the Blazor, and then they only showed up when the user was authorized to see them.
Comments
Post a Comment