How to Add Basic Authentication to an ASP.NET Core Application: OAuth Security - Part 1

preview_player
Показать описание

We have a look at integrating Basic authentication into an ASP.NET Core application.

The whole point of setting up Basic authentication is so we can use it when we set up OAuth security.

First, we have a look at how Basic authentication works, and how we can add it to the HTTP request. By adding a base 64 encode of the username and password, we can add it to the Authorization HTTP request header.

Afterwards, we go ahead and write our own attribute. This attribute will be governed by a handler that we will write specifically for Basic authentication.

Finally, we set up a new authentication scheme specifically for Basic authentication. In-addition, we will go ahead and create a new authorisation policy.

📖 Learn .NET and C# with our online courses 📖

#aspnetcore #basicauthentication #oauth
Рекомендации по теме
Комментарии
Автор

Brilliant Tutorial Thank You.
Well explained, easy to code along too and it worked perfectly.
It's the starting point i needed 😀

oShaydo
Автор

Really clean and to the point. Great video. Thank you

sahawndada
Автор

Thanks Much for the tutorial, Actually helped me :)

manisharajan
Автор

This has been the tutorial that has helped me, thank you very much for sharing it

meylinblanco
Автор

That is very basic and from scratch! Thx a lot.

eryksiejka
Автор

Thank you so much for the video, it was very helpful !! :D

adrianestevez
Автор

I repeated everything step by step, but the login window does not appear. What am I doing wrong?

blagumur.kratos
Автор

Awesome could you make a video about OAuth2 authentication with Github using sessions?

stefanbogdanovic
Автор

Hi David, have you tried writing some unit test or integeration test for BasicAuthenticationHandler to test AuthenticateAsync?

I tried it using NSubstitue to mock objects. Getting null reference exception on handler.InitializeAsync. Any clue?

var context = new DefaultHttpContext();

var scheme = new AuthenticationScheme(_options.ToString(), null,

await _handler.InitializeAsync(scheme, context);
var result = await _handler.AuthenticateAsync();

abi
Автор

Thank you for the tutorial. Just one concern.. can we by default set the authorization header in the request header. right now while the opening the static file at first we will not have the authorization header and since in the response we add the authorization header.. the next time we can see the login page.

hariharanmurugan
Автор

How can i redirect to login page not login windows as you done

duongvanhung