Secure Your .NET Application With Keycloak: Step-by-Step Guide

  Рет қаралды 27,595

Milan Jovanović

Milan Jovanović

Күн бұрын

Пікірлер: 124
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Do you want to simplify your development process? Grab my free Clean Architecture template here: bit.ly/3Andaly Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
@AndresValencia1985
@AndresValencia1985 4 ай бұрын
I'm writing to you from Colombia. You solved a problem I had been dealing with for several days while trying to integrate a small .NET project using Net Aspire Components
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Ha! I'm glad this was helpful to unblock you 😁
@alexlo2621
@alexlo2621 4 ай бұрын
Great explanation of Keycloak for authentication and authorization! The setup and configuration steps were clear, and your examples made complex concepts easy to grasp. Looking forward to more in this series-super excited to dive deeper!
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Great to hear!
@d3vil5oldier
@d3vil5oldier 4 ай бұрын
Please more series on keyclock. In the past i tried to implement this but I was defeated. Thank you for sharing your knowledge.
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Will do! I have a few more ideas for topics to cover
@d3vil5oldier
@d3vil5oldier 4 ай бұрын
@@MilanJovanovicTech Awsome. Please show how to connect to a postgres database and manage user roles/permissions
@19balazs86
@19balazs86 4 ай бұрын
This is a great video series! I remember in the past searching for content about Keycloak, but nothing compares to this.
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Glad it was helpful! And I'm glad some results are coming up for Keycloak now 😁
@Comphonia
@Comphonia 4 ай бұрын
More of Keycloak please. I'm excited for the series! 😊
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
More to come!
@matejskerjanc7703
@matejskerjanc7703 4 ай бұрын
Awesome as usual, I'd love to refresh auth code flow and claims transformations knowledge. It's been a while, you're best for this:))
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
I think I covered refresh token in previous Keycloak video, and I have a separate one on claims transformation
@alibabapour7418
@alibabapour7418 Ай бұрын
excited for keycloack series 🔥
@MilanJovanovicTech
@MilanJovanovicTech Ай бұрын
What do you think about it?
@alibabapour7418
@alibabapour7418 Ай бұрын
@MilanJovanovicTech it's offering so many benefits and suitable for microservices imo while everyone struggling with clouds alternative, it's free and could be run as a isolated containter can't ask more
@alibabapour7418
@alibabapour7418 Ай бұрын
@MilanJovanovicTech well it's offering so many benefits and suitable for microservices imo while everyone struggling with clouds alternative, it's free and could be run as a isolated containter, can't ask for more.
@alibabapour7418
@alibabapour7418 Ай бұрын
well it's offering so many benefits and suitable for microservices imo while everyone struggling with clouds alternative, it's free and could be run as a isolated containter, can't ask for more.
@alibabapour7418
@alibabapour7418 Ай бұрын
@MilanJovanovicTech well it's offering so many benefits and suitable for microservices imo while everyone struggling with clouds alternative, it's free and could be run as a isolated containter, can't ask for more. I'm considering for applying authorization using keyclock Do you think it's worth it?
@anatolia23
@anatolia23 4 ай бұрын
Better to use cookie (http only) authentication for enhanced security, particularly when your client is a SPA. Utilise cookies for communication between the client and the API Gateway, and JWTs for interactions between the API Gateway and downstream services. Good content btw!
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
That could be something I cover in a future video
@JollyGiant19
@JollyGiant19 4 ай бұрын
@@MilanJovanovicTech cookie based jwt authentication, if you could. It gives us all the security of cookie auth with the statelessness of JWTs
@edandersen
@edandersen 4 ай бұрын
This was fantastic. Thanks!
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Sure thing!
@akashkarve1991
@akashkarve1991 4 ай бұрын
Nice video. Waiting for more microservice scenario on Keycloak. Cheers :)
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Working on it
19 күн бұрын
thanks for sharing Milan, it helped to me also..
@MilanJovanovicTech
@MilanJovanovicTech 18 күн бұрын
You're welcome!
@fahimahmedali
@fahimahmedali 4 ай бұрын
Another nice video on Keyclock, keep em coming
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Much appreciated!
@aloussase
@aloussase 4 ай бұрын
12:56 you said let's navigate to the SwaggerUI when navigating to the JaegerUI 14:16 you said let's open up swagger when opening postman You see Swagger everywhere 🤣
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Ok ok get out of here 😂
@lpsoldier357
@lpsoldier357 4 ай бұрын
Awesome video as always. Please do a video using microsoft entra as identity provider. There are few examples about it online.
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Great suggestion!
@rzaip
@rzaip 3 ай бұрын
Would love to see how you set this up for production and deploy to Azure (or any other cloud provider).
@MilanJovanovicTech
@MilanJovanovicTech 3 ай бұрын
Azure Container Apps?
@manliomarchica4911
@manliomarchica4911 4 ай бұрын
Great video as usual! Do you use Implicit flow for the sake of simplicity ? I know that it is not recommended to use the implicit flow for security reason
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Yes, could've also used auth code flow just the same
@nagibatorbatcka86
@nagibatorbatcka86 4 ай бұрын
Hello Milan, What do you think about making video where you implement your own IdentityServer ? For example with Duende IdentityServer.
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Perhaps, we'll see
@rickjarr
@rickjarr 4 ай бұрын
Awesome series!
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Glad you think so!
@piotrc966
@piotrc966 4 ай бұрын
why in "MetadataAddress" localhost:18080 not working? And must be docker address?
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Because these containers are in a docker network
@MixuD
@MixuD 4 ай бұрын
Both the API and Keycloak are running inside Docker Compose, which automatically sets up an internal Docker network. Within this network, each container (in this case, the API and Keycloak) has its own isolated "localhost" that refers only to itself. To enable communication between containers, you need to use the service names defined in the Docker Compose file. These service names act as hostnames, allowing the containers to find and communicate with each other. So instead of using "localhost" to connect to Keycloak, we need to use the Keycloak service name from the Docker Compose file. This is because "localhost" within the API container refers only to the API itself, not to other containers like Keycloak. Enjoy this visual representation: Host Machine → [ Docker Network { API Container Keycloak Container } ]
@piotrc966
@piotrc966 4 ай бұрын
OK. Thanks. I also guess that 'iss' address (localhost:18080) in token keycloak takes automatically from client request, because it has no access to this adress itself.
@Santalucesguy
@Santalucesguy 4 ай бұрын
How can I connect keycloack to a sql sever db? I’m still stuck with this Identity provider. Thanx
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Check here: www.keycloak.org/server/db
@Santalucesguy
@Santalucesguy 4 ай бұрын
@@MilanJovanovicTech thanks! btw do you know if there is a way to custumize the view screen where keycloak asks for credentials?
@smnb6652
@smnb6652 4 ай бұрын
Could you add the requests as http files next time? I'm neither using Swashbuckler nor Postman and getting the basic request was not clear for me.
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Yeah, good suggestion. Thanks!
@ydswd2003
@ydswd2003 4 ай бұрын
Great video! Could you implement an extra field in the user record?, gender, for example. Another interesting topic, although outside the C# scope, could be "Custom Themes". I would like to see more Keyclok videos. Thank you so much!
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
That's a good idea for a future video
@heikenem
@heikenem 4 ай бұрын
Great video, congrats!
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Thanks!
@FastForward-i4s
@FastForward-i4s Ай бұрын
Hi Milan, great video as always. I have a question: Instead of having both the proxy and the api doing auth, do you think its a valid/feasible idea to have the gateway forward just the claims downstream when the authentication is successful? that way there is less duplication and the api could simply process the relevant header for claims info.
@MilanJovanovicTech
@MilanJovanovicTech Ай бұрын
Yes, this makes sense. But we have to make sure that the internal APIs can't be accessed from the outside world. Otherwise, we'd be introducing a security risk.
@JoseMuinos
@JoseMuinos 2 ай бұрын
Super usefulll! Any plans on creating a guide for Azure AD B2C authentication? I've seen lots of companies migrating to 2FA auth these last months so im curious: is it Azure AD B2C the best option? Thank's for the content!
@MilanJovanovicTech
@MilanJovanovicTech 2 ай бұрын
It's probably the best option if you're on Azure
@sunzhang-d9v
@sunzhang-d9v 4 ай бұрын
What should I do if the repository needs to be associated with a user table, and I don't need to create a user table locally?
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
I'm not sure what you're asking here
@thiembaotrinh4309
@thiembaotrinh4309 4 ай бұрын
I'm curious if Keycloak can point to an external IDP (AAD, PingId,...) for authentication and automatically sync the users from the external IDP to Keycloak. It would help a lot for enterprise applications.
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Not sure, let's me check
@okanyurt345
@okanyurt345 4 ай бұрын
Thank you 🙏
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
You bet
@marko5734
@marko5734 4 ай бұрын
Can you create video how would auth work in microservices architecture?
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Yes. It'll be very similar to this, with just copying the auth config in a few services.
@marko5734
@marko5734 4 ай бұрын
@@MilanJovanovicTechThat would be great
@SaifKhan-s5i
@SaifKhan-s5i 4 ай бұрын
Thank you for the amazing video. Will you prefer to use Keycloak or Microsoft Identity Server where you use user manager, role manager etc. Thank you.
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
I mostly use Keycloak. I always had to "fight" with Identity to get it to do what I want.
@nguyendavid4285
@nguyendavid4285 24 күн бұрын
How to get this source of video?
@MilanJovanovicTech
@MilanJovanovicTech 23 күн бұрын
Currently, all code is shared here: www.patreon.com/milanjovanovic
@aymenbachiri-yh2hd
@aymenbachiri-yh2hd 3 ай бұрын
Thank you so much
@MilanJovanovicTech
@MilanJovanovicTech 3 ай бұрын
Any time
@FabianoNalin
@FabianoNalin 2 ай бұрын
Is it possible to integrate Swagger into YARP?
@MilanJovanovicTech
@MilanJovanovicTech 2 ай бұрын
Yes, but it's a bit tricky. You should be able to configure Swagger UI to fetch the Open API descriptions from the downstream APIs.
@MkYentertainment
@MkYentertainment 2 ай бұрын
Why no confidential client?
@MilanJovanovicTech
@MilanJovanovicTech 2 ай бұрын
We could use it, but we're still exposing the secret on the UI
@ryankruger7401
@ryankruger7401 3 ай бұрын
Love the series, I am trying to setup according to your video but I have fought for hours with this issue, after getting the bearer token and requesting from the /me endpoint. Bearer error="invalid_token", error_description="The signature key was not found"
@MilanJovanovicTech
@MilanJovanovicTech 3 ай бұрын
Looks like Metadata endpoint is unreachable
@adiatyt11
@adiatyt11 9 күн бұрын
@@MilanJovanovicTech Same issue, how to fix this? I have a dockerised setup
@vinp2007
@vinp2007 4 ай бұрын
just wanted clarification on authentication, so if i had multiple microservices each offering different api calls how would i use the authentication to make sure that all the api calls have a valid authentication/ authorization? Would i use the proxy approach just a little confused.
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Typically yes, you'd have a proxy/gateway in front all your services
@bjarnenilsson80
@bjarnenilsson80 2 ай бұрын
Ok this might be slightly ot, but I've noriced something,in every toturuazl where and postgresql is involved it spins up it's own posrgres container, which is fine if you have only one application running on a host, but what happens if you have 10, now all of a sudden you are runing 10 instances of postgresql, I might be stubid, but doeasn't this chew up a significant amount of ram ? Wouuldn't ir be better to gave a common postgresql container for all apps, where each app has their own db and postgresql user?
@MilanJovanovicTech
@MilanJovanovicTech 2 ай бұрын
This is much simpler for demos
@yuravertsimaga6012
@yuravertsimaga6012 4 ай бұрын
Great! Thanks! What about passwordless approach, could we implement some sms code verification with Keyclock?
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Yes we can, adding that to the list
@myschool1361
@myschool1361 4 ай бұрын
requesting for the RBAC using keycloak
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
On my list
@esrefcagataydogan8308
@esrefcagataydogan8308 4 ай бұрын
Hi Milan, I am developing an application using Keycloak and Spring Boot. I have implemented OTP login and Google Sign-In, but there is an issue. If a user has previously logged in with OTP and then tries to log in with Google using the same email, I get a "user already exists" error (federated identity account exists). In this case, I want the accounts to be merged. In other words, the user should be able to log in using both OTP and Google Sign-In with the same email. Could you help me with this?
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Damn, that is a great question. I don't have an answer right now, but let's see if I can dig up some docs.
@dimzinnatov7242
@dimzinnatov7242 4 ай бұрын
Do part 2, where you will create an SPA that will send a request to the API please
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
Sure, sure
@АнтонМешков-ф8х
@АнтонМешков-ф8х 4 ай бұрын
I'm sorry but it doesn't work error when trying to login Bearer error="invalid_token", error_description="The signature key was not found"
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
You must've done something different
@goodgod17
@goodgod17 3 ай бұрын
Антон, как починил?)
@goodgod17
@goodgod17 3 ай бұрын
а то я с этой штукой уже устал. Буду рад, если подскажешь)
@ryankruger7401
@ryankruger7401 3 ай бұрын
Yeah I got the same
@ryankruger7401
@ryankruger7401 3 ай бұрын
@goodgod17 have you managed to fix the issue
@geepy5708
@geepy5708 15 күн бұрын
I’m not sure the essence of this is for a user to be redirected back to keyCloak to register or sign up. There has to be a way an api authenticates with keyCloak and returns a token. It’s a poor user Experience to have an app that authenticates on another interface(keyCloak).
@MilanJovanovicTech
@MilanJovanovicTech 14 күн бұрын
You can customize the login screen to make it look identical to your website. If not - you can implement the OAuth flow yourself
@geepy5708
@geepy5708 14 күн бұрын
@MilanJovanovicTech Alright. Please try to cover this part in another keycloak video. It's indeed very robust
@HeitorGiacomini
@HeitorGiacomini 3 ай бұрын
posting before finishig to see the video, i have been stuck on it for 3 months.
@MilanJovanovicTech
@MilanJovanovicTech 3 ай бұрын
Do you have it figured out now?
@HeitorGiacomini
@HeitorGiacomini 3 ай бұрын
@@MilanJovanovicTech not yet. i'm trying to configure .net core back end and angular front but errors is confusing.
@imranaliikram462
@imranaliikram462 4 ай бұрын
Nice 👍.. Can you make videos on Keycloak 2 factor authentication via email and sms ? I was working on it and its required custom providers in java for this functionality and i was jot able to complete that ..
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
As soon as possible!
@DonLiang-n7w
@DonLiang-n7w 2 ай бұрын
It's very nice tutorial! Thank you! Can you please share your code also?
@MilanJovanovicTech
@MilanJovanovicTech 2 ай бұрын
Code is here: www.patreon.com/milanjovanovic
@guilhermelinosp
@guilhermelinosp 4 ай бұрын
repo?
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
This code is Patreon-only
@edwincarlsson9014
@edwincarlsson9014 4 ай бұрын
Had an issue where the JWT did not get returned correctly to the dotnet authentication system. Something about a mismatch in models in the Token / JsonWebToken namespaces. I had to assign SignatureValidator in the TokenValidationParameters to return a new Microsoft.IdentityModel.JsonWebTokens.JsonWebToken from the encoded JWT parameter to that SignatureValidator delegate. Don't know why this happened, I followed your solution step by step.
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
That's quite unique 🤔
The Simplest Way to Add Keycloak Authentication to Your .NET API
14:29
Milan Jovanović
Рет қаралды 8 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
Build an AI Movie Night Recommendation Tool
1:13:50
DataCamp
Рет қаралды 922
Front-end web development is changing, quickly
3:43
Fireship
Рет қаралды 1,4 МЛН
#PKCE explained - Proof Key for Code Exchange for #OAuth2 Authz Code Grant | Niko Köbler (@dasniko)
17:00
Niko Köbler - Expert for Keycloak IAM & SSO
Рет қаралды 838
Secure Your .NET API in 15 Minutes: JWT Authentication Tutorial
15:05
Milan Jovanović
Рет қаралды 29 М.
Keycloak Is AWESOME! Single Sign On Made Easy!
25:05
Jim's Garage
Рет қаралды 123 М.
Swagger is Gone in .NET 9! Replace It With This.
9:34
Nick Chapsas
Рет қаралды 93 М.
NGINX Explained - What is Nginx
14:32
TechWorld with Nana
Рет қаралды 306 М.
Multiple JWTs in .NET: How to Implement Multi-Token Authentication
17:40
The Fix For Your Database Performance Issues in .NET
9:12
Nick Chapsas
Рет қаралды 89 М.
Exceptions Are Extremely Expensive… Do This Instead
17:15
Milan Jovanović
Рет қаралды 50 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН