Secure Your Microservices with Keycloak | OAuth2 & JWT | Spring Cloud Gateway

Techno Town Techie
14 Sept 202423:31

Summary

TLDRThis video introduces Keycloak, an open-source identity and access management tool, highlighting its advantages for securing microservices. It explains how Keycloak simplifies authentication and user management by handling user storage, authentication, and authorization without requiring coding. Keycloak offers features like user federation, customizable login pages, social login, and fine-grained authorization. The video also demonstrates Keycloak integration with a Spring Boot microservices application using Docker. A step-by-step guide explains setting up security configurations, JWT token management, and API integration with Keycloak, showcasing its ease of use and scalability.

Takeaways

  • 🔑 Keycloak is an open-source identity and access management tool that simplifies adding authentication to applications and securing microservices.
  • 🔒 Keycloak handles authentication and authorization, eliminating the need for applications to store or authenticate users themselves.
  • 📱 Keycloak offers features like user federation, strong authentication, user management, and fine-grained authorization, which are all customizable.
  • 🔐 Keycloak enables easy integration of login forms, recovery passwords, and two-factor authentication without any coding changes.
  • 🧑‍🤝‍🧑 Single Sign-On (SSO) with Keycloak allows users to access multiple applications after a single authentication.
  • 💡 Keycloak supports identity brokering and social login integration, making it easy to authenticate users using social networks.
  • 🗄️ User Federation allows Keycloak to integrate with external identity stores like Active Directory and relational databases.
  • ⚙️ Keycloak supports standard authentication protocols like OAuth 2.0, OpenID Connect, and SAML 2.0.
  • 🔄 The script explains how to integrate Keycloak with Spring Boot applications, including necessary configurations and settings.
  • 🧩 A detailed walkthrough is provided on configuring Keycloak clients, client scopes, and roles, and integrating it with a Spring Cloud API Gateway for secure service access.

Q & A

  • What is Keycloak?

    -Keycloak is an open-source identity and access management tool that adds authentication to applications and secures microservices with minimal effort. It provides features like user federation, strong authentication, user management, and fine-grained authorization.

  • What are the advantages of using Keycloak for authentication?

    -Keycloak simplifies the authentication process by handling user storage and authentication, eliminating the need to manage these in the application. It supports user federation, customizable login pages, password recovery, and two-factor authentication, along with single sign-on and strong session management.

  • How does Keycloak help with Single Sign-On (SSO)?

    -Keycloak allows users to authenticate once and access multiple applications without needing to log in again. It manages sessions across applications, providing strong session management capabilities and reducing the need for individual login forms in applications.

  • What is user federation in Keycloak?

    -User federation in Keycloak refers to the capability of integrating with external identity stores, such as LDAP or Active Directory, to manage user authentication and storage externally. Keycloak has built-in support for these services.

  • What protocols does Keycloak support?

    -Keycloak builds on industry-standard protocols, supporting OAuth 2.0, OpenID Connect, and SAML 2.0 for secure authentication and authorization.

  • How does Keycloak handle authorization?

    -Keycloak provides fine-grained authorization services, allowing you to manage permissions for services through the admin console. It also supports role-based and policy-based access controls to meet different authorization needs.

  • What are some of the main features provided by Keycloak?

    -Keycloak offers features like single sign-on (SSO), user federation, social login, identity brokering, customizable login pages, password recovery, strong session management, and clustering capabilities for scalability.

  • How can Keycloak be installed using Docker?

    -Keycloak can be installed with Docker by running a simple Docker command. The command includes specifying a username, password, Keycloak version, and optionally changing the default port. After running the command, Keycloak will be accessible via the provided port.

  • What is a Realm in Keycloak?

    -A Realm in Keycloak is a tenant that isolates different applications and users from each other. Each Realm can have its own clients, users, and configurations. You can create realms for specific applications, employees, or customers.

  • How does Keycloak integrate with a Spring Boot application?

    -To integrate Keycloak with a Spring Boot application, dependencies like 'Spring Security' and 'Resource Server' are added. The Keycloak server handles user authentication, and the Spring Boot application uses the JWT token for authorization. Configuration steps involve setting up the security filter chain, enabling JWT decoding, and defining access rules.

Outlines

00:00

🔑 Introduction to Keycloak and Its Benefits

The speaker introduces Keycloak, an open-source identity and access management tool that simplifies authentication and user management in applications. Keycloak secures microservices with minimal effort by handling user storage and authentication. It offers features like customizable login pages, two-factor authentication, password recovery, and user federation, integrating easily without modifying the application's code. Keycloak also provides single sign-on (SSO) and strong session management, allowing users to access multiple applications with one login.

05:00

🛠️ Installing Keycloak Using Docker

The speaker explains how to install Keycloak using Docker. A command is provided to run Keycloak locally, specifying the port number and setting an admin username and password. Once installed, Keycloak can be accessed using a web interface where users can manage clients, client scopes, realms, roles, users, and sessions. The concept of realms is introduced, with realms serving as isolated tenants for different applications or user groups.

10:01

🏢 Configuring Realms and Clients in Keycloak

This section delves into configuring realms and clients in Keycloak. The speaker explains that a realm represents an isolated tenant, and each application can have its own realm. Clients, such as web, mobile, or native applications, interact with Keycloak for authentication. The speaker walks through creating a client within a realm, configuring client authentication, setting up roles, and defining client scopes, which allow adding reusable groups of claims to tokens issued to clients.

15:03

🔑 Keycloak Authentication Flow and Integration with Spring API Gateway

The speaker describes the authentication flow when using Keycloak with an API. When a user attempts to access a protected resource, they are redirected to the Keycloak login page. After successful authentication, the user receives an authorization code and access token, which are used for API requests. The API verifies the token and grants access. This process is demonstrated through the integration of Keycloak with a Spring API Gateway, providing seamless authentication for microservices.

20:05

🚀 Setting Up JWT-Based Authentication for API Gateway

In this final section, the speaker explains how to configure JWT-based authentication for an API Gateway using Keycloak. They walk through the process of adding Spring Security and Resource Server dependencies to a project, configuring JWT decoding, and setting up a security filter chain in the Spring application. The steps to disable cross-site request forgery (CSRF) and permit specific requests like those to the Eureka server are also outlined. The speaker demonstrates testing the setup by obtaining an access token and using it to authenticate API requests.

Mindmap

Keywords

💡Keycloak

Keycloak is an open-source identity and access management tool that adds authentication and security to applications with minimal effort. It enables developers to offload tasks like storing and authenticating users, allowing them to focus on the application logic. In the video, Keycloak is discussed as a way to secure Spring Boot microservices by managing user identities and authorizations centrally.

💡Authentication

Authentication is the process of verifying the identity of a user. In the context of the video, Keycloak handles user authentication for applications, eliminating the need for developers to implement login forms or store user credentials. This reduces security risks and simplifies the management of user access across multiple applications.

💡Authorization

Authorization determines what an authenticated user is allowed to do within an application. The video explains how Keycloak can be used to manage fine-grained permissions, ensuring that different users have appropriate access to specific resources. This is crucial for securing applications, especially in multi-user environments.

💡Spring Boot

Spring Boot is a framework that simplifies the development of Java-based applications, particularly microservices. In the video, the integration of Keycloak with Spring Boot is highlighted, showing how Keycloak can be used to secure Spring Boot microservices by handling authentication and authorization.

💡Single Sign-On (SSO)

Single Sign-On (SSO) allows users to authenticate once and gain access to multiple applications without logging in again. The video emphasizes Keycloak’s ability to provide SSO, improving user experience by reducing the need to repeatedly log in to different services.

💡Identity Federation

Identity Federation refers to Keycloak’s ability to integrate with external identity providers, such as Active Directory or LDAP. This allows organizations to manage user identities across multiple systems. The video mentions how Keycloak supports external identity stores through this feature, making it easier to unify user management.

💡Social Login

Social Login enables users to authenticate using their social media accounts, such as Google or Facebook. In the video, Keycloak’s capability to integrate social login into applications is discussed, allowing developers to offer users a convenient way to sign in without creating new accounts.

💡Client

In Keycloak, a client is an entity that requests authentication on behalf of a user. It can be a web, mobile, or native application. The video explains how clients interact with Keycloak to secure themselves and provide Single Sign-On functionality. Examples include Spring Boot microservices acting as clients.

💡Realm

A Realm in Keycloak is a tenant, representing an isolated space where a set of users, clients, roles, and groups are managed. The video describes how realms are created for different applications or user groups, allowing for isolated management of users and permissions. Each realm is independent of others.

💡OAuth 2.0

OAuth 2.0 is an industry-standard protocol for authorization. Keycloak supports OAuth 2.0, which allows applications to delegate user authentication to an external service. In the video, OAuth 2.0 is mentioned as one of the protocols Keycloak uses to handle secure communication and authorization between clients and the server.

Highlights

Keycloak is an open-source identity and access management tool that simplifies authentication for applications and microservices.

Keycloak manages authentication, eliminating the need for applications to store and authenticate users.

Keycloak supports features such as user federation, strong authentication, user management, and fine-grained authorization.

Keycloak offers fully customizable login pages, password recovery, and multi-factor authentication, without requiring code changes in applications.

Single sign-on (SSO) is supported by Keycloak, allowing users to access multiple applications with a single login.

Keycloak can integrate with social login services, making it easier to add social network authentication to applications.

User federation in Keycloak allows integration with external identity stores like LDAP or Active Directory.

Keycloak supports industry-standard protocols such as OAuth 2.0, OpenID Connect, and SAML 2.0.

Fine-grained authorization services are available in Keycloak, offering more control over permissions and policies.

Keycloak is lightweight, easily scalable, and supports clustering for high performance.

Keycloak provides a master realm by default and allows creating additional realms to isolate applications or user groups.

Clients in Keycloak are entities such as web or mobile applications that request Keycloak for user authentication.

Client scopes in Keycloak allow creating reusable groups of claims that can be added to tokens issued to clients.

Keycloak provides a detailed admin console, which enables the management of clients, roles, users, and sessions.

Keycloak can be installed using Docker, allowing for quick setup and local deployment.

Transcripts

play00:03

I hope everyone is doing good okay so

play00:05

today I would like to discuss about key

play00:07

clock here okay so what is the key clock

play00:09

and what are the advantages of using

play00:11

like key clock here so why exactly this

play00:13

key clock is came to the picture and

play00:14

after that I'm going to discuss about um

play00:17

spring boot with key clock integration

play00:19

as well okay so now so what is a key

play00:23

clock key clock is nothing but it's a

play00:24

open source identity and access

play00:26

management tool here okay so basically

play00:29

it will add the authentication to

play00:31

applications and secure your

play00:33

microservices with minimum effort okay

play00:36

so let's say that you have a spring boot

play00:37

application like microservices

play00:39

application so if you want to add like

play00:41

authentication or authorization so if

play00:43

you want to provide the security then

play00:44

you have to be store the users and

play00:47

authenticating the users so all those

play00:49

information you have to be taken care at

play00:51

your application right so that is the

play00:54

main advantage of using key clocks let's

play00:56

say that if you are using key clocks no

play00:58

need to deal with the storing the users

play00:59

or authenticating the users at your

play01:01

application so these two things will

play01:04

taken care by this key clock okay so

play01:06

apart from this key clock provides user

play01:08

Federation and strong authentication and

play01:10

user management and F and fine grind

play01:14

authorization and much more capabilities

play01:17

okay so K loock provides like fully

play01:19

customizable login pages and Recovery

play01:23

passwords and accepting the terms and

play01:25

lot more okay so all of these Futures

play01:28

provided by a ke clock can easily

play01:29

integrate your application without any

play01:32

coding at all okay so by delegating the

play01:35

authentication of user to the key clocks

play01:37

you don't worry about the authentication

play01:39

mechanism so safely store the passwords

play01:42

right so you can enable like two Factor

play01:44

authentication without having to make

play01:46

changes to the application okay so uh

play01:50

this is the added advantage of using the

play01:52

key clock

play01:55

and sorry key clock also provides like

play01:59

single sign up so with storing session

play02:01

management okay so

play02:05

session K clock also provides like

play02:07

single sign on with like strong Mission

play02:09

uh strong session management

play02:11

capabilities okay so apart from this it

play02:14

will provide like single sign on option

play02:16

as well so key clock also provides like

play02:18

single sign on with strong session

play02:20

management capabilities it means that

play02:21

allowing the users to access the

play02:23

multiple applications while only having

play02:25

to authentication once okay so that's

play02:29

what it is saying so authenticate with

play02:30

KCK loock rather than individual

play02:32

application so this means that your

play02:33

application don't have to deal with

play02:35

login forms so authenticating the users

play02:36

and storing the users so once you log

play02:39

into K clock user don't have to be

play02:41

loging again to access the different

play02:43

applications okay and apart from this it

play02:45

will provide like identity brokering and

play02:47

social login as well okay so let's say

play02:49

that if you want to integrate with the

play02:50

social login in your application so then

play02:52

what you have to do what you have to do

play02:54

is it just matter of like selecting The

play02:56

Social Network you want to add it so no

play02:59

code changes is required to your

play03:01

application okay so that is the added

play03:04

advant advantage of this key CLA and

play03:07

apart from this user Federation so if we

play03:09

talking about the user Federation here

play03:11

right so what is the user Federation U

play03:14

user Federation means in key clocks the

play03:15

term user Federation refers to the

play03:18

capability of integrating with external

play03:20

identity stores okay so you can think of

play03:23

Lop is an example of candidate for

play03:26

integrating via the user Federation men

play03:28

so that's what it is saying so key clock

play03:30

has a built-in support to connecting

play03:32

with existing L like active directory

play03:34

servers we can also Implement your own

play03:36

provider so if you have users in other

play03:39

stores such as a relational database

play03:41

okay so apart from this uh it has like

play03:44

couple of consoles as well so so they

play03:47

can enable and disable couple of Futures

play03:49

here so you can go through this consoles

play03:51

as well and apart from this standard

play03:53

protocols okay ke clock provides like

play03:57

some uh standard protocols okay so uh

play04:01

KCK loock Builds on industry standard

play04:04

protocol supporting like w 2.0 open ID

play04:07

connect and S 2 okay and apart from this

play04:11

authorization Services okay so it's uh

play04:14

if role based authorization does not

play04:16

cover your needs then K clock provides

play04:18

fine Grand authorization Services as

play04:19

well okay so this allows you to manage

play04:22

the permissions for for all your

play04:24

services from the key clock admin

play04:25

console and give you the power of to

play04:29

exact what the policies that you

play04:31

required here okay so key clock is a

play04:34

lightweight and easily uh to install

play04:37

okay that that's required for your

play04:39

application okay so you can easily scale

play04:42

where clustering capabilities as well so

play04:44

apart from this key clock will Prov like

play04:46

couple of features so here they have

play04:47

listed out like couple of features

play04:48

single sign on some standard protocols

play04:51

centralized management adopters okay L

play04:53

up and active directory social login

play04:55

identity brokering high performance okay

play04:58

clustering so you can just go through

play05:00

this key clock official documentation so

play05:02

that like you'll get good idea here okay

play05:05

so uh apart from this so let's say that

play05:08

if you want to be install um key clock

play05:12

here so there is one option so so you

play05:14

can go you can install with Docker as

play05:16

well okay so what you have to do is

play05:20

um okay so this is the docker command so

play05:23

you can run Docker command with this

play05:26

okay Ed Z Ed Z so which will run on Ed

play05:29

Zer so if you want to change the port

play05:30

number you can change here and apart

play05:32

from this KY call here you need to

play05:34

provide the KY clock username of the

play05:36

password so I have provided like admin

play05:38

and admin here and apart from this this

play05:40

is the click clock key clock version and

play05:42

apart from this you can provide like the

play05:44

profile here okay so that's it once you

play05:48

entered this it will start like

play05:50

downloading this key clock in your local

play05:52

system

play06:00

okay so once it is successfully started

play06:03

then what you have to do is so you can

play06:06

just check it out by using this code

play06:11

number okay and you have to log in with

play06:15

admin and admin here okay so here you

play06:19

can see like couple of options here you

play06:21

can see the clients client Scopes realm

play06:23

roles and users groups and sessions and

play06:25

events all the stuff okay so by default

play06:28

so there there is one opt that is cck

play06:30

clock real alarm here okay what is a

play06:33

master real alarm here okay by default

play06:35

it will has like master real alarm so

play06:38

and apart from this you have to be

play06:40

create like one real here okay I will

play06:43

explain one by one here okay so what is

play06:46

the real alarm here so the real alarm is

play06:48

nothing but you can think of the real

play06:49

alarm as a tenant okay so the first

play06:51

thing you will want to do is create a

play06:54

realm for your application and your

play06:56

users okay so realm is a fully isolated

play06:59

from the other realm so because so you

play07:02

can create one realm for your enter

play07:04

application and another realm for your

play07:07

uh your employees uh and another realm

play07:10

for like external applications and the

play07:11

customers okay so here I'm going to

play07:14

create one realm for my application okay

play07:17

so what I will do is uh I will take like

play07:21

um

play07:23

my um yeah my key

play07:28

clock application

play07:31

okay so that's it you can just create it

play07:34

and once you create it right so it will

play07:36

by default here my key clock application

play07:39

realm has been selected under this so

play07:41

there are like couple of options we have

play07:43

a clients client Scopes realm roles okay

play07:45

we have to create this all those stuff

play07:48

here so before that what is the client

play07:49

here the clients are entities okay so

play07:52

that request key clock to authenticate a

play07:55

user okay so most often the clients are

play07:57

a web or mobile or like native

play08:00

applications that want to use a key

play08:01

Cloud to secure themselves and provide a

play08:04

single sign on Solutions okay so uh

play08:08

apart from this we have a client scope

play08:10

as well so what is a client scope so if

play08:12

we talking about client scope U that

play08:14

client scope will allows to creating a

play08:17

reusable groups of CLS that are added to

play08:21

token issued to the client okay so you

play08:23

can also Define an optional client

play08:25

Scopes here so in this way so you should

play08:27

specify the optional client with the

play08:29

scope parameter here okay apart from

play08:33

this we have a roles as well okay so we

play08:35

have we have a roles so usually like if

play08:37

you're talking about the roles usually

play08:39

represented role a user that has in the

play08:42

either your organization or like in the

play08:44

context of of your application so if

play08:47

we're talking about the role like for

play08:48

example user can be granted a

play08:50

administrator role therefore so they can

play08:53

access and perform like any action on

play08:55

any resource in your application okay

play08:58

and apart from this we have like some

play09:01

you can create the users and groups and

play09:03

sessions here okay and apart from this

play09:06

you can see like uh realm settings here

play09:09

as well okay and uh what I will do is I

play09:13

will create the client first okay so

play09:16

just create client

play09:18

so

play09:21

my key

play09:23

clock client okay so let me copy this

play09:27

and provide the name and description

play09:29

also I'm providing the same Okay click

play09:31

on the next so here you can see the

play09:34

capability configuration so if you want

play09:36

to enable the client authentication you

play09:38

can just enable here and apart from this

play09:41

so there is a authorization okay option

play09:44

as option also is available here here

play09:46

the authentication flow is there so here

play09:48

you need to select a couple of options

play09:50

so if you want to um go with like

play09:52

standard flow okay direct access crun

play09:55

you can just go through this and so if

play09:57

you don't want this so here we have

play09:59

enable the client authentication right

play10:00

so I just want to be go through service

play10:03

account roles here okay just check this

play10:07

and apart from this we have what 2.0

play10:09

device authorization grind and YDC okay

play10:12

couple of options is there so you can

play10:13

just go through this and click on the

play10:15

next so here root URL so you need to

play10:18

Define the root URL here okay so my

play10:22

spring Cloud API Gateway is running on

play10:25

9090 so I'm just defining here so home

play10:28

you also same and just save this okay so

play10:33

that's it and once you save this you can

play10:35

see the credentials here there is a

play10:37

client secret will be generated so you

play10:39

have to use this client secret okay so

play10:42

if you want to create any roles you can

play10:43

just create the roles and map to this

play10:46

clients here okay so apart from this we

play10:48

have a some other Advanced options as

play10:50

well you can just go through for time

play10:53

being I'm not going to create any

play10:55

advanced options here okay so that's it

play10:58

and

play11:00

so uh I would like to discuss one more

play11:03

thing here okay um yeah clock

play11:07

architecture so whenever like user um

play11:10

sends like authentication requests okay

play11:13

so then so the user tries to access a

play11:16

protected resources and it is redirect

play11:18

to the key clock login page right so the

play11:21

key clock verifies the users credentials

play11:23

if it is successful then redirects them

play11:25

back to the okay authorization code okay

play11:28

and ACC token okay so uh then user sends

play11:34

uh then the user sends are like AP

play11:36

request of the access token here so the

play11:38

application included the application

play11:40

will be included the access token in the

play11:42

authorization header when when making

play11:44

the API requests here right so then so

play11:47

the W metadata will be extracted here

play11:49

and apart from this it will validate the

play11:51

token here okay so the API verifies the

play11:55

uh token and grants the access if it is

play11:57

required then then it it will be written

play12:00

the response to user here okay so this

play12:02

is how the overall key clock

play12:04

architecture will look like when you are

play12:06

integrated key clock with the

play12:08

API okay okay so now let's integrate

play12:12

this key clock with our API here okay so

play12:15

let's open our code so uh before that so

play12:19

here actually we already go through this

play12:22

how this spring Cloud API gateaway is

play12:25

integrated with Ura server and your

play12:28

product Service as well well okay so if

play12:30

you not uh went through this videos

play12:32

please go through so I already have this

play12:35

videos in my playlist in microservices

play12:36

3.0 playlist please go through that and

play12:39

now so what I'm going to do is I already

play12:42

started this um urea server okay and

play12:45

product service okay and so this product

play12:49

service is straightforward so we have a

play12:51

uh some Endo which will return like

play12:53

products here okay and apart from this

play12:56

we have a spring Cloud AP Gateway Okay

play12:58

so this spring Cloud API Gateway will

play13:01

routes okay that product service through

play13:03

this API Gateway okay

play13:06

and now let's open this

play13:10

um urea server here okay so now

play13:19

let's let's hit this

play13:23

okay so yeah now it's returning the

play13:27

product Okay so this product service

play13:30

actually coming through this AP Gateway

play13:33

AP Gateway is running at 9090 okay this

play13:35

is products okay so this is ring like

play13:38

list of products here okay so this is

play13:39

working fine now what I'm going to do is

play13:42

to integrate this key clock basically

play13:43

like two dependencies are required right

play13:46

so uh let's open this spring initializer

play13:49

here okay so here I need like um Spring

play13:54

Security okay dependency and apart from

play13:57

this I need a

play14:00

resource server okay so just explore

play14:02

this here you will see this two

play14:04

dependencies right so this two

play14:06

dependences just copy this two

play14:08

dependencies here and let's open the

play14:11

pom.xml file here so in the pom.xml file

play14:14

just include these two

play14:17

dependencies okay that's it and apart

play14:21

from this what we have to do is uh in

play14:24

application. ml file basically we need

play14:26

to add this um our is your url uh

play14:30

application. properties so what I'm so

play14:33

here so basically we have a security

play14:36

okay so what to Resource server and

play14:40

after that we have to add like JWT JWT

play14:43

issuer Ur here okay so the issue URI so

play14:46

what we need to do is just open our key

play14:49

clock here okay so in

play14:53

the itm settings okay so here you can

play14:57

see this open a open ID endpoint

play15:00

configuration just click on this okay so

play15:03

there are like couple of options are

play15:05

available here I mean like couple of

play15:06

endpoints okay so here we have like

play15:09

issuer authorization endpoint token

play15:11

endpoint okay apart from this we have a

play15:13

grand types supported we have a couple

play15:15

of grand points uh Grand types so so it

play15:19

depends on your requirement so you can

play15:20

choose like this Grand types here okay

play15:23

so first like we need this issue

play15:25

endpoint okay so let's copy this and

play15:28

going back to our code and just add this

play15:31

here okay and now so we are ready to use

play15:35

this isure urri here right now what we

play15:38

have to do is uh we need to add like one

play15:42

configuration here okay so that is our

play15:45

security configuration so now I'm going

play15:48

to create one configuration class okay

play15:50

so just um inside this config package

play15:55

I'm going to create like a

play15:57

web security okay so configuration here

play16:02

okay so what I will do is I will add

play16:05

like the of configuration okay and after

play16:09

that I will create one of the bean here

play16:11

okay so this Bean basically will have a

play16:15

security filter so let's take uh public

play16:19

okay so let's remove this space here so

play16:22

here what I will do is I will take a

play16:25

security security filter chain Okay so

play16:28

so this will have like HTTP security

play16:31

okay let's take HTTP security as a

play16:34

parameter here and after that so here so

play16:38

what I will do is I will take HTTP so

play16:41

first like I need to disable this uh

play16:43

csrf that is like cross site request

play16:46

forgery okay so I will disable this so

play16:49

to disable this basically I need like

play16:52

some HTTP security related filter okay

play16:55

configure okay and so let's take this

play16:59

and let's disable this okay so once you

play17:03

disable this uh uh what we have to do is

play17:06

we have to like um allow like this urea

play17:09

server here okay so urea server should

play17:12

not be authenticated here so to do this

play17:15

basically I will take um authorized HTTP

play17:19

request here okay inside this authorized

play17:21

like HTTP request what I will do

play17:27

is so

play17:30

requests so this requests okay so here

play17:35

what I will do is I will take uh request

play17:38

matchers so inside this request matcher

play17:40

we can provide like

play17:41

urea okay matcher here and

play17:46

so what I will do is I will move to the

play17:49

next line okay so here we have option

play17:51

like permit all so this will permit like

play17:53

eura server here and apart from this we

play17:57

have like any other request so let's say

play17:59

that we have any request so that will

play18:02

authenticate okay so apart from Thea

play18:04

server any other request has to be

play18:06

authenticated here okay and so

play18:10

authenticated and after that so what we

play18:13

have to do is uh we have like other

play18:16

option like w um sorry so w here we have

play18:23

W resource server okay let's take that

play18:25

this W resource server and we have like

play18:30

um what here okay so this

play18:35

what okay so inside this what we have

play18:39

like JWT okay so here here what we need

play18:42

to do is we have to be configur like JWT

play18:44

based configuration okay so let's take

play18:46

customizer so this customizer will have

play18:49

a with defaults option okay so that's it

play18:52

can build

play18:53

this okay so here you can just return

play18:57

this and add

play18:59

exception to this method signature okay

play19:02

so this is straightforward right so what

play19:04

we did is first like we have disabled

play19:06

this um cross site request forgery and

play19:09

after that we have all like euroka

play19:11

server and apart from this eura server

play19:13

like other services we are

play19:14

authenticating here okay

play19:18

and what server we have Pro like JWT

play19:21

based like configuration okay and after

play19:24

that we have to provide like one more

play19:26

Bean Okay so that being

play19:30

basically

play19:31

okay uh JWT decoder okay so JWT decoder

play19:38

so this JWT decoder basically will take

play19:40

what um okay what resource server

play19:44

properties so let's take properties as

play19:48

par name here and so let's return return

play19:52

um JWT decoders okay so we have another

play19:57

class called like JWT decoders okay

play20:00

let's take this and uh this JWT decoders

play20:04

basically from is location so if you

play20:06

want to provide like isure location so

play20:08

you can provide the isure location here

play20:10

so properties from the properties we

play20:13

have to fetch that get JWT okay get ISS

play20:18

URI okay so that's it so now so you can

play20:22

just start this uh

play20:24

application okay so here we can see some

play20:28

error HTTP Security in our

play20:32

configuration okay let's see this okay

play20:35

so we forgot to enable uh web security

play20:38

okay just add this annotation and let's

play20:40

start

play20:42

this okay so this time it started uh

play20:45

without any errors okay um I will take

play20:49

one new endpoint here okay and so HTTP

play20:54

9090 product so this is my API Gateway

play20:58

end point just hit this so you will see

play21:00

like 401 unauthorized here okay so uh in

play21:04

the authorization tab so there is a

play21:05

option called okay what 2.0 we have to

play21:09

select this so here actually we have a

play21:11

couple of options configure new token

play21:13

here okay so here we have to be add like

play21:17

uh some token names okay so this is my U

play21:20

my app token okay and apart from this

play21:23

here we have a grand type so you have to

play21:25

take like uh depends on your requirement

play21:28

you can choose like what kind of grand

play21:30

type you required here so I need like

play21:31

client credentials here okay so as we

play21:34

discussed like in like in open ID

play21:37

configurations we have a couple of grand

play21:38

types right so there also we have to

play21:40

choose different depends on your

play21:42

requirement and apart from this we have

play21:44

a access token uh URL here okay so that

play21:47

access token URL so you have to get it

play21:50

from that open ID configuration so

play21:52

access token this one so just copy this

play21:55

this is token in find so go back here

play21:59

and let's paste here okay and after that

play22:03

we have a client ID so what is our

play22:04

client ID so the client ID is your

play22:08

client so this is my client my key clock

play22:12

client here okay just provide here and

play22:15

after that there is a credential tab so

play22:17

here you can see the client secret okay

play22:19

just copy this and coming back here and

play22:22

just paste okay and we have a Scopes and

play22:26

scope is optional here so depends on

play22:28

your requirement go for this code and

play22:30

after that we have a client

play22:31

authentication so what is the client

play22:33

authentication here so now here we have

play22:36

a two options send as a basic Au header

play22:38

or like send client credentials in body

play22:41

okay so I'm just taking as like send as

play22:43

a basic o header okay so once you

play22:46

selected this get new access token

play22:48

button is there just click on this and

play22:51

it will take like couple of seconds here

play22:54

okay to generate this

play22:55

token so it's generated the token so so

play22:58

this is my access token so if I want to

play23:00

use this token access token in my API

play23:05

header then click on this used token

play23:08

okay and now it's has been added to okay

play23:12

here the token section and just click on

play23:15

send so then you are getting the

play23:18

response right so this is how this SK

play23:21

clock will be work okay so that's it so

play23:25

if you like this video please go ahead

play23:26

and like if you haven't subscribed my

play23:27

YouTube Channel please please go ahead

play23:28

and subscribe YouTube channel thanks

play23:30

thanks for watching

Rate This

5.0 / 5 (0 votes)

Ähnliche Tags
KeycloakSpring BootAuthenticationSingle Sign-OnUser ManagementMicroservicesOAuth2Identity ManagementAPI GatewayJWT
Benötigen Sie eine Zusammenfassung auf Englisch?