How to SECURE My Microservices Architecture (REACTJS + SPRING CLOUD GATEWAY) With Keycloak

Поділитися
Вставка
  • Опубліковано 11 гру 2024

КОМЕНТАРІ • 98

  • @manee427
    @manee427 Рік тому

    Finally, find what I looked for. Really thanks and perfect video. keep doing more please

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому +1

      Thank you for watching! I will keep doing more video. Don't forget to share to channel to your network 😅

  • @wanggewg
    @wanggewg 5 місяців тому +3

    Could you please make video to demo BFF pattern ( Backend for FrontEnd). BFF is thought more secure than PKCE flow.

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  5 місяців тому

      I first need to investigate a little bit more about it

    • @camilosilva1010
      @camilosilva1010 29 днів тому

      Thumbs up for this :)
      I'm currently struggling regard this approach

  • @camilosilva1010
    @camilosilva1010 29 днів тому

    Your videos are amazing! Keep doing this great job!

  • @katacode
    @katacode Рік тому

    Thank you very much. You explain very complicated things in very clear language

  • @PatrikM
    @PatrikM Рік тому +1

    Hey Sergio, thanks for a great tutorial. I've been looking for one covering both a backend and frontend connected to keycloak. I was wondering how you would implement redirect when logging out? As of this tutorial the logout button works but it doesn't take you back to the index page. I've been trying to use your solution for the signin callback, but with no luck. How would you implement the callback for logout?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      Hi Rekishi, thanks for your interest.
      I didn't try to the logout, but it's a good question. Did you check the settings of the frontend oidc-client library post_logout_redirect_uri (github.com/IdentityModel/oidc-client-js/wiki)? Maybe just adding this configuration when creating the frontend client is enough. If that's the case, let me know your feedbacks.

    • @PatrikM
      @PatrikM Рік тому +1

      @@TheDevWorldbySergioLema Thanks for the quick reply. I managed to solve it for now by adding the "post_logout_redirect_uri:" field to settings when creating the UserManager, then setting the same url in Keycloak and copying your signin-callback.html page and remaking it for using "signoutRedirectCallback()"

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      Glad it worked so easily!

  • @damjuve13
    @damjuve13 Рік тому

    now i know how to implement pkce authorization with react ! thanks !

  • @codingstyle9480
    @codingstyle9480 Рік тому

    Hi, It seems, in this scenario, the role of the cloud gateway api is just to convey the request to different resource server(backend resources) endpoints? It has no contribution to the security. Here the first line of action takes place with the user requesting the react frontend, which redirects the user to keycloak login page if the user not logged in? In some scenarios where the cloud gateway is a part of the security and is the first line of action, and its called BFF(backend for front end) , if I am not mistaken. Is that right?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      Yes, in this scenario the backend is acting as a BFF, you're right. The security is split between the frontend (as the client server) and the private backend (as the resources server). The API gateway is only there to redirect the requests

  • @Mateusz-dl1mr
    @Mateusz-dl1mr Рік тому +1

    Great tutorial! But I have one question, what if there is multiple backend resources? Do i need to add security config in each microservice?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      Yes, all the resources servers you have need the configuration to be able to talk with Keycloak.

    • @Mateusz-dl1mr
      @Mateusz-dl1mr Рік тому

      @@TheDevWorldbySergioLema ok but what if there is for example 50 resources that have to be secured? Copy paste code in each? 😅

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      Yes 😅. But you can also add a Config Server, ua-cam.com/video/p65u4t26BBc/v-deo.html

    • @Mateusz-dl1mr
      @Mateusz-dl1mr Рік тому +2

      @@TheDevWorldbySergioLema I see but it wouldnt be better to configure api gateway as resource server and there provides configuration to secure some of services? It seems to be best solution if Spring Cloud Api Gateway is an entry point

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому +1

      You're right, i will try to implement this solution

  • @daniellaerachannel
    @daniellaerachannel Рік тому

    in your project you're still on version 2.7.1; any update concerning spring 3.0.2 and keycloak? thanks

  • @cyper0418
    @cyper0418 Рік тому +1

    Agree, I think resource server brings us too much overhead given microservices in reality hides behind the gateway and frontend cannot access it directly. So I would like to see a solution where we only parse the token in gateway once via some filter. And then pass the the resolved userId to microservcies through some http header(Not pass token, this way we don't need to set each and every micro-service as a resource server.

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому +1

      Yes, I will try to implement this way. I've already done something similar, with a single JWT, but not with OAuth2 and Keycloak.

    • @istvanduro3394
      @istvanduro3394 Рік тому

      Hy! Any update on this? Sorry for bothering you.

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      It's planned, but i didn't started yet

  • @stanleynyekpeye5318
    @stanleynyekpeye5318 4 місяці тому

    Thanks for the video. However, I have a question.
    Is there a way to login to keycloak without redirecting to the keycloak login page? I have a custom login screen in my ReactJS app and I want to make use of it instead.

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  4 місяці тому

      Yes, you can configure a custom login page in Keycloak

    • @stanleynyekpeye5318
      @stanleynyekpeye5318 4 місяці тому

      @@TheDevWorldbySergioLema Ok. How do I go about it?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  4 місяці тому

      I didn't try it, but this seems to be what you're looking for: www.baeldung.com/keycloak-custom-login-page

  • @treefrog9392
    @treefrog9392 Рік тому

    How do you allow post requests using this keycloak flow?
    I am always getting back a missing csrf token error. Any idea how to configure this or to disable csrf?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      To allow the POST requests, make sure to allow the CORS in the application.yml of the Gateway.
      About the CSRF, I din't anything particular, it was disable by defautl.

  • @rustemzinnatullin6941
    @rustemzinnatullin6941 6 місяців тому +2

    ITM - Всем здарова! Вам тоже сложно даются видосы на инглише?

  • @andreamonte851
    @andreamonte851 Рік тому

    Hi! I have a doubt. I have a Web site that must access protected API. I have a Spring Cloud gateway and some microservices and here I implemented the authorization based on roles.. Now I followed the way to register the Gateway as confidential client on Keycloak and store in it client_id and secret_id. I was wondering if this way was better and what the differences were. Thanks

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      Using the authentication with Keycloak is very useful if you have many different applications (clients) which need this same authentication. If you only have one application (client), maybe putting all the authentication logic inside may reduce the complexity.
      But, using Keycloak is using a string authentication system, OAuth2. Which was tested for many years.
      Using you own authentication system means that you must take care of the security breaches.
      What I recommend? It depends on you (and your team):
      * if you need the same authentication system for many application -> use Keycloak
      * if you don't know much about security breaches or authentication systems -> use Keycloak
      * otherwise -> use a simple authentication system inside you already existing application
      Hope this will help you

    • @andreamonte851
      @andreamonte851 Рік тому

      @@TheDevWorldbySergioLema what the client scope is for? Is it mandatory?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому +1

      It's not mandatory. You can let the value to profile, name, email or openid.
      It says what kind of information you want to fetch from the User's profile.

  • @poomc5462
    @poomc5462 Рік тому

    Really great tutorial! Is there a way to create my own React login screen that could be used with keycloak? Thanks!

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      Thanks! Yes you can create your own React login page. Then, in Keycloak, you can select the login page where the user will be redirected.

  • @rajeevjayaram4981
    @rajeevjayaram4981 Рік тому

    Great Video. It helped me a lot...We are planning to use Spring 3.1 Authorization server . I am tryin to use the React Code to connect to Spring Auth server. Login Screen is comming and the login is successful.. but in the end I am getting the following error in the signin-callback.html : No matching state found in storage. Could you please tell me how to fix this issue. With Keycloak it is fine....Thanks

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      Thank you Rajeev. I've been looking around and found this information (github.com/IdentityModel/oidc-client-js/issues/1044). It seems to be the cookies.

  • @maxi331
    @maxi331 10 місяців тому

    Hello! i'm trying to replay this situation and i have a CORS issue. Any idea?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  10 місяців тому

      Do you use the Spring Cloud Api Gateway? Or directly Spring Security? If you use Spring Security, check this other video where I configure the CORS: ua-cam.com/video/phs90_s0Mjk/v-deo.html

  • @RohitMore-t5q
    @RohitMore-t5q 14 днів тому

    what if my frontend request will be with https ?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  13 днів тому

      This should change. You need to add the SSL certificate to Keycloak and the Gateway

  • @AlexanderKurguzkin
    @AlexanderKurguzkin Рік тому

    Thank you, very useful!

  • @poseidonzf
    @poseidonzf Рік тому

    Could gateway be also a resource server so it can validate tokens? In my case I get Cors error: Missing allow origin header in preflight request, I already tried several ways to enable Cors with no luck.

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому +1

      Yes, someone already told me about this alternative. I will try to make another video with this solution.
      About the CORS problem, you must configure them in both the api gateway and keycloak. Try with different browsers (sometimes they act differently).

    • @mariomatejovic2190
      @mariomatejovic2190 Рік тому

      Hey , have you been able to mange that cors issue ?

  • @arunadl143
    @arunadl143 11 місяців тому

    great tutorial!!.

  • @techlead_ashu
    @techlead_ashu 9 місяців тому

    TUSM. Great content. Just one thing - you have been writing OIDC, Open ID Connect ... but you pronounce OI-SEE-d, lol xD

  • @sinanbenlibas161
    @sinanbenlibas161 11 місяців тому

    So can I login without redirecting?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  11 місяців тому

      Do you mean having a login form integrated inside the frontend without the redirection to the login page of Keycloak?

    • @sinanbenlibas161
      @sinanbenlibas161 11 місяців тому

      @@TheDevWorldbySergioLema just like you said

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  11 місяців тому

      I don't if configuring a custom login page in Keycloak is enough. I never did it, so I can't tell you if it works.

    • @sinanbenlibas161
      @sinanbenlibas161 11 місяців тому

      @@TheDevWorldbySergioLema thank you i have last question You have installed keycloak legacy version . Would it be a problem if we use the release version?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  11 місяців тому

      I don't thing there is much difference

  • @jonathanmoore4837
    @jonathanmoore4837 5 місяців тому

    Thanks for video

  • @ismailforeveryone6889
    @ismailforeveryone6889 Рік тому

    Good job keep going

  • @telongrestur9110
    @telongrestur9110 Рік тому

    logout redirect not working??

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      I didn't try the logout. Have you any message describing the error? Or nothing is shown?

    • @telongrestur9110
      @telongrestur9110 Рік тому

      @@TheDevWorldbySergioLema Like logout was working but it was not redirect back to app, I have to set post logout redirect url and it worked. Thanks for the video.

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      Thanks for your feedback!

  • @techlead_ashu
    @techlead_ashu 9 місяців тому

    Thank you so much :)

  • @cristianpadilla2069
    @cristianpadilla2069 Рік тому

    Hi sergio, have a question, what about registration?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      It must be done directly in Keycloak.

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      You can see it in this video, ua-cam.com/video/YHWfJHKGYGI/v-deo.html

    • @cristianpadilla2069
      @cristianpadilla2069 Рік тому

      @@TheDevWorldbySergioLema thanks sergio, so every user that wants to use my application must first register on keycloak? let´s say an E-comerce

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      Yes, that's the goal of an SSO, you use keycloak just to sign, not to register. If you want to register the users in your application and manage their accounts, it's another authentication system you need

  • @EugeneZimin
    @EugeneZimin 7 місяців тому

    Video is nice, but if you had less content switched back and fort to your face - it would be way better.

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  7 місяців тому

      Some parts need more explanations, some parts are just coding.
      I explain while what I'm doing in a more dynamic way than just talking in front of a screen for 5 minutes
      I'm sorry, but that's my way to do videos

  • @DivinePositives
    @DivinePositives Рік тому

    If possible to rubyonrails

  • @ThePazuzu
    @ThePazuzu Рік тому

    Why do all keycloak teachers think we all use java?

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому +1

      🤣 In fack, my channel is mainly about Java, and I've done a few videos with Keycloak. Which language are you looking for?

    • @ThePazuzu
      @ThePazuzu Рік тому

      @@TheDevWorldbySergioLema I'm a Rails or Express guy so maybe JavaScript or Ruby.

    • @ThePazuzu
      @ThePazuzu Рік тому

      @@TheDevWorldbySergioLema the keycloak documentation is terrible and I've wasted weeks trying to figure out how to integrate a rails api with a react frontend with keycloak.
      One of the worst documented projects I've ever seen.

    • @TheDevWorldbySergioLema
      @TheDevWorldbySergioLema  Рік тому

      It's not well documented. But once you've started and configured Keycloak, what you need to know is the OAuth2 protocol with whatever language.