Implementing API Key Authentication in ASP.NET Core

Implementing API Key Authentication in ASP.NET Core

Nick Chapsas

1 год назад

70,073 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Shehan Samarasinghe
Shehan Samarasinghe - 16.10.2023 13:14

Great video. Superb content. Thank you !!!

Ответить
Antonio Buyukliev
Antonio Buyukliev - 02.10.2023 18:32

Hi Nick, appreciate the work you do. One question about the filter of the minimal api. If we have another middleware the request stops first in it and then into the filter?

Ответить
blackpaw29
blackpaw29 - 17.09.2023 02:24

Thank you, very interesting and easy to implement with your clear details. Looks appropriate for a use case I have.

Couple of questions 😁

- Can you safely mix auth schemes, i.e I have a multi-tenant minimal api that users authenticate to via Azure B2C oauth2, but I need to add a simple API key access for a few endpoints, for service apps to use. I could use client credentials flow or application api's, but there's the problem of distributing/revoking api keys and I want to issue them dynamically depending on the tenant the service apps belong to.

- Can you restrict access to a SignalR server using these?

- Swagger - can it handle multiple auth schemes?

Ответить
johnsitka
johnsitka - 15.09.2023 18:44

Great help, exactly what I needed. Thanks tons. Since adopting Blazor Server then finding Minimal API's I can now build Api's without MVC "and" secure them. I remember first hearing of WebSocket so many years ago, throw in Entra, Microsoft Graph, and Application Proxy we now have flying cars for the enterprise.

Ответить
Amanda Santi
Amanda Santi - 15.09.2023 18:41

To get around the dependency injection problem you can create a custom attribute that extends from TypeFilterAttribute, which then passes typeof(MyFilter) to the base constructor. From there the system will allow you to use DI in your filter.

Ответить
Gianluca Rosadini
Gianluca Rosadini - 12.09.2023 17:39

You are great! Thank you!

Ответить
Micro Tech
Micro Tech - 09.09.2023 18:33

Hi, can you come up with a vidwo where you can demonstrate how to Authorize same endpoint using either inbuilt jwt bearer or api key at the same time? So,how we can add custom authentication along with inbuilt authentication schemes and regiater at startup. Thanks

Ответить
Skillamu
Skillamu - 01.09.2023 13:27

Very good and detailed explination on this topic, great video!

Ответить
Alonso Ureña
Alonso Ureña - 31.08.2023 03:56

I was looking for the second approach, so sad 😂😂😂

Ответить
HYIP Investor Khmer
HYIP Investor Khmer - 24.08.2023 08:54

how to use AllowAnonymous?

Ответить
Nattapon Aiyawan
Nattapon Aiyawan - 07.08.2023 10:00

This video is difficult to understand and video editing is inconsistent with the content..

Ответить
Jephren Naicker
Jephren Naicker - 20.07.2023 16:15

broooo,! so cool!

Ответить
Alireza Arttam
Alireza Arttam - 14.07.2023 23:48

Thanks ❤

Ответить
Yogesh Kajala
Yogesh Kajala - 29.06.2023 19:25

Hi Nick, that is very nice. Just a quick thought about how can I separate consumers(apps), like I want to have separate api key for each app trying to use api. Quick thought is to include app name along with key, I grab the app name and check the key. Any batter way?

Ответить
Livinghighandwise
Livinghighandwise - 23.06.2023 20:44

In your example, once the APIKeyMiddleware - public async Task method runs, and authentication is successful, it doesn't redirect to my Homecontroller in order to run the my Post method and continue with the request. How do I get it to direct to my post request in my Homecontroller?

Ответить
DasMaffin
DasMaffin - 07.06.2023 19:32

So if I have an app that connects to thousands of users authentication is something I dont need, did I get that right?

Ответить
PooyaKeshvari
PooyaKeshvari - 06.06.2023 10:37

thank you we love you

Ответить
Biznes Lupa
Biznes Lupa - 31.05.2023 08:25

can you give us the book name or tutorial where did you learn this all?

Ответить
Mert Ali
Mert Ali - 22.05.2023 15:07

thanks

Ответить
Musica
Musica - 16.05.2023 00:25

This breaks swagger documentation.

Ответить
Hueseyin Guendogan
Hueseyin Guendogan - 19.04.2023 14:06

Great!

Ответить
Falsa Poetica
Falsa Poetica - 15.04.2023 20:29

This was awesome, thanks Nick!
Just wondering, is there a reason for not using the IMiddleware interface when implementing the ApiKeyAuthMiddleware class?

Ответить
Onur Micoogullari
Onur Micoogullari - 09.04.2023 21:19

Great video Nick, as always! A tip to others: the same principal can be used to enforce client certificate based auth, minus the Swagger UI integration. This way, you can easily enforce different types of auth on different scopes within the same API.

Ответить
majid ismail
majid ismail - 06.04.2023 22:13

Hi Nick
Amazing video, I have a question about minimal api swagger authorize button option
How to pass different keys with the same button
I have bearer token some set of endpoint allowed with one token and other set of endpoints use another type of token.
How can we address it so Authorise button worked

Thank you

Ответить
patrick breslin
patrick breslin - 03.04.2023 23:45

Nick, I purchased your zero to hero minimal API course... the discord link is broken.... is that a mistake or did you shut it down?

Ответить
Jerry Jeremy
Jerry Jeremy - 31.03.2023 21:11

Thanks Nick, i need this

Ответить
Roberto Guere
Roberto Guere - 30.03.2023 00:00

excelente video

Ответить
Aegir Tomasson
Aegir Tomasson - 26.03.2023 01:23

Brilliant, thanks!

Ответить
Matteo Trapani
Matteo Trapani - 23.03.2023 18:24

Hi Nick! First of all thank you very much for your videos! They are soooo interesting and you actually taught me a lot since when I started following you :D
I have a question about this approach: why yoi didn't mention the AuthenticationHandler approach?

Ответить
Kay Meister
Kay Meister - 22.03.2023 14:00

Great video! Thanks a lot for your efforts, Nick! You're great

Ответить
Oyede Oluwafunbi
Oyede Oluwafunbi - 20.03.2023 02:44

Great Video!!!!!!!!

Ответить
ecitah pi
ecitah pi - 19.03.2023 03:09

the longest app. 18 minutes in my life :D thank you for the explanation!

Ответить
veracsthedefiled
veracsthedefiled - 06.03.2023 23:11

I was hoping to use api keys with Identity framework, I recall seeing your .NET core 2 & 3 playlist, and in comments section there you said we can look up the API key to find which user it belongs to, while that can work I think it will conflict with JWT auth since its configured as a filter, and [Authorize] attributes won't work with API keys, and as well as I think looking up the DB on every request is expensive.

Ответить
Roman Marusyk
Roman Marusyk - 05.03.2023 04:38

why not use AuthenticationHandler and the default [Authorize]?

Ответить
King Æthelstan
King Æthelstan - 01.03.2023 18:31

Excellent tutorial - thanks

Ответить
Cagri Kolsuz
Cagri Kolsuz - 01.03.2023 10:59

That's great explanation. Thanks.

Ответить
Silas Peters
Silas Peters - 22.02.2023 00:36

This was exactly what I needed. Now maze makes way more sense!

Ответить
John A
John A - 17.02.2023 06:31

I wonder is it possible the have the Authorization Filter attribute on the class level, but then override that with another Authorization Filter at the method level. That was by default the methods are safe, unless otherwise indicated.

I know you can set Filter orders but they still both get fired.

Ответить
tonykidv2
tonykidv2 - 15.02.2023 03:28

is it possible to use [AllowAnonymous] annotation to bypass the middleware?

Ответить
Stephen Miller
Stephen Miller - 14.02.2023 08:44

Id love to see example of storing multiple API Keys in database and comparing the header key to those in the database. I have a scenario where I will have multiple clients using the API and would like to have a different API Key to give them access to their own data. Great video !

Ответить
S L
S L - 13.02.2023 18:09

Would love a video on building a throttle mechanism where its not waiting in memory but in a queue or database

Ответить
Julian Segura
Julian Segura - 13.02.2023 17:33

I finally can understand this concept to it's fullest. Thanx for the great content

Ответить
Carsten Berggreen
Carsten Berggreen - 13.02.2023 13:22

Tak! Brilliant video! Covers all my thoughts and questions about API Keys in one video!

Ответить
Simple Gameplay
Simple Gameplay - 12.02.2023 22:32

OMG asp net core si solo cool 🥹🥹

Ответить
Cristiano Salvatori
Cristiano Salvatori - 12.02.2023 11:39

Always great!!!!

Ответить
Jacob Duenke
Jacob Duenke - 11.02.2023 21:02

Am I crazy? I’ve always found the swagger ui has the lock icons mixed up. Why would the lock be LOCKED when the api is unlocked and authorized for use??

Ответить
Ivandro Jao
Ivandro Jao - 11.02.2023 15:08

Hello Nick can you please do a video on difference between .UseRouteing() and .UseEndpoints()?

This thing is everywhere stackoverflow / reddit but still not clear enough!

Ответить
JeffNikelson
JeffNikelson - 11.02.2023 09:44

one of your best videos so far 👌🏻

Ответить