SlideShare a Scribd company logo
1 of 29
Securing Microservices
WSO2 Identity Server
Anupam Gogoi - Associate Technical Lead
Pre-requisites
• JDK 8
• Maven
• Eclipse or IntelliJ
• WSO2 Identity Server 5.7.0
Lab Exercise 1 - Create Microservice
Part 1
We are going to create a simple Microservice in Spring
Boot. The service contains a resource protected by
OAuth2.
Part 2
Configure WSO2 Identity Server as OAuth2/OpenID
authorization server.
Solution Lab Exercise 1
Part 1
Creating a Spring Boot microservice.
Code repository
https://github.com/anupamgogoi-wso2/wso2-summit
High Level Overview
Spring Boot Microservice
• Visit the site https://start.spring.io/ and create a project with dependencies Web and
Security.
• Import the project in Eclipse/IntelliJ and add one more dependency by hand in the
pom.xml
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.0.6.RELEASE</version>
</dependency>
• Add your logic.
• https://github.com/anupamgogoi-wso2/wso2-summit
Spring Boot - Configure Auth. Server
Note that for client id and client secret you need to use valid username password from
WSO2 Identity server.Here i have used default admin username/password.According to
this configuration resource server will use OAuth2 introspection API to validate the
token.
security.oauth2.client.client-id=admin
security.oauth2.client.client-secret=admin
security.oauth2.client.access-token-uri=https://localhost:9443/oauth2/token
security.oauth2.client.user-authorization-uri=https://localhost:9443/oauth2/token/authorize
security.oauth2.client.scope=openid
security.oauth2.resource.filter-order=3
security.oauth2.resource.user-info-uri=https://localhost:9443/oauth2/userinfo
security.oauth2.resource.token-info-uri=https://localhost:9443/oauth2/introspect
security.oauth2.resource.prefer-token-info=true
Spring Boot - Run
The important thing is to pass client truststore details while executing the jar file.Spring
security will use SSL connection to talk with Authorization server to validate the access
token.The spring boot runtime should be provided with certificate store to find out the
authorization server certificate authority and trust it.
java -Djavax.net.ssl.trustStore=/Users/anupamgogoi/softwares/wso2/is/wso2is-
5.7.0/repository/resources/security/client-truststore.jks 
-Djavax.net.ssl.trustStorePassword=wso2carbon 
-jar /Users/anupamgogoi/git/wso2-summit/spring-oauth2-microservice/target/spring-oauth2-microservice-
1.0.0.jar
Solution Lab Exercise 1
Part 2
Configure WSO2 Identity Server as OAuth2
Authorization Server
High Level Overview
• We will use a simple 3 entity
example 1) User, 2) Application
server, and 3) Authentication server.
• The authentication server will
provide the JWT to the user. With
the JWT, the user can then safely
communicate with the application.
Configure WSO2 Identity Server
• Log into the IS (admin/admin)
• Navigate to Service
Providers menu and click
add.
Add Service Provider - IS
Provide Basic Information for the
Service Provider.
Eg.
Service Provider Name: OAUTH2
Inbound Authentication Configuration
Click Inbound
Authentication
Configuration and expand
OAuth/OpenID Connect
Configuration.
OAuth/OpenID Connect Configuration
Configure OAuth2. Choose Token
Issuer as Default (OAuth2).
Note that we can choose JWT
also. (Next lab)
OAuth/OpenID Connect Configuration
Once configuration is saved you
will be provided with the Client
Key and Client Secret.
Microservice Resource
The Spring Boot microservice contains a resource protected by
OAuth2.
GET http://localhost:8080/app/products
To access this resource, an Access Token must be provided in
the Authorization header.
Generating Access Token - Postman
• Token URI of the Identity Server,
https://localhost:9443/oauth2/token
• Use password grant_type and provide necessary
details. Note that the client_id & client_secret are
generated while adding the Service Provider in the
IS.
• Make sure to send the following header,
Content-Type: application/x-www-form-urlencoded
Generating Access Token - CURL
curl -u <CLINET_ID>:<CLIENT_SECRET> -k 
-d "grant_type=password&username=admin&password=admin" -H "Content-Type:application/x-www-form-urlencoded" 
https://localhost:9443/oauth2/token
Invoke Microservice
curl -k http://localhost:8080/app/products -H "Authorization: Bearer <<ACCESS_TOKEN>>
Lab Exercise 2
Using JWT to access the protected resource of the
microservice.
Solution - Lab Exercise 2
We are going to use the same Spring Boot microservice
with the same resource. Only thing we will need to change
is in the Identity Server to generate JWT.
Configure identity.xml - IS
● Open the <IS_HOME>/repository/conf/identity/identity.xml file and set the <Enabled>
element (found under the <OAuth>,<AuthorizationContextTokenGeneration> elements) to true
as shown in the code block below.
● Add the following property under <OAUTH> section to use the JWT Token Builder instead of
the default Token Builder.
<IdentityOAuthTokenGenerator>org.wso2.carbon.identity.oauth2.token.JWTTokenIssuer</IdentityOAuthTokenGenerator>
Configure identity.xml - IS
• Configure the “audiences” parameter as mentioned below so that the token includes information
about the intended audiences who can use the generated token for authenticating the user.
<EnableAudiences>true</EnableAudiences>
<Audiences>
<Audience>${carbon.protocol}://${carbon.host}:${carbon.management.port}/oauth2/token</Audience>
</Audiences>
• Configure a meaningful value to the <IDTokenIssuerID> parameter in the identity.xml file
<IDTokenIssuerID>my-jwt-token</IDTokenIssuerID>
• Start the IS
sh wso2server.sh
Configure Identity Provider - IS
Go into Identity-> Identity Providers and click on “Add”.
Configure Identity Provider - IS
Identity Provider Name—This needs to be the same value as the <IDTokenIssuerID> value you configure at the identity.xml
file since this value will be the issuer ID of the JWT token. Here the value is given as “apim-idp” to match the above mentioned
parameter.
Identity Provider Public Certificate—Here you need to upload the public certificate of the WSO2 Identity Server in a pem
file format. The Identity Provider Public Certificate is the public certificate belonging to the identity provider. Uploading this is
necessary to authenticate the response from the identity provider. This can be any certificate. Since we are using WSO2 Identity
Server as the IDP we can generate the certificate using the below mentioned commands.
Create/Import Certificate
• Open your Command Line interface, go to the
<IS_HOME>/repository/resources/security/directory. Run the following command.
keytool -export -alias wso2carbon -file wso2.crt -keystore wso2carbon.jks -storepass
wso2carbon
Click Choose File and navigate to this location in order to select and upload this file.
• Alias—You need to give the clientID (client key) of the service provider which you will
configure in the WSO2 Identity Server here. This will be checked when verifying the JWT
token.
OAuth/OpenID Connect Configuration
• Create a new Service Provider e.g JWT
• Choose any valid Url in the Callback Url
field.
• Choose Token Issuer as JWT.
Get JWT & Invoke Service
You need to first get a JWT token from the WSO2 identity server by using the token endpoint
with the password grant type. You can use the below mentioned curl command to get a JWT
token,
curl -u <CLIENT_ID>:<CLIENT_SECRET> -k 
-d "grant_type=password&username=admin&password=admin" -H "Content-Type:application/x-www-form-urlencoded" 
https://localhost:9443/oauth2/token
Use the token in Authorization header in the request to access the protected resource of the
microservice,
curl -k http://localhost:8080/app/products -H "Authorization: Bearer <<JWT_TOKEN>>"
THANK YOU
wso2.com

More Related Content

What's hot

__Cloud_CNA_MSA_Service+Data+InferenceMesh 소개-박문기@메가존클라우드-20230320.pptx
__Cloud_CNA_MSA_Service+Data+InferenceMesh 소개-박문기@메가존클라우드-20230320.pptx__Cloud_CNA_MSA_Service+Data+InferenceMesh 소개-박문기@메가존클라우드-20230320.pptx
__Cloud_CNA_MSA_Service+Data+InferenceMesh 소개-박문기@메가존클라우드-20230320.pptx문기 박
 
높은 가용성과 성능 향상을 위한 ElastiCache 활용 팁 - 임근택, SendBird :: AWS Summit Seoul 2019
높은 가용성과 성능 향상을 위한 ElastiCache 활용 팁 - 임근택, SendBird :: AWS Summit Seoul 2019 높은 가용성과 성능 향상을 위한 ElastiCache 활용 팁 - 임근택, SendBird :: AWS Summit Seoul 2019
높은 가용성과 성능 향상을 위한 ElastiCache 활용 팁 - 임근택, SendBird :: AWS Summit Seoul 2019 Amazon Web Services Korea
 
mykola marzhan - jenkins on aws spot instance
mykola marzhan - jenkins on aws spot instancemykola marzhan - jenkins on aws spot instance
mykola marzhan - jenkins on aws spot instanceDariia Seimova
 
CI/CD pipelines on AWS - Builders Day Israel
CI/CD pipelines on AWS - Builders Day IsraelCI/CD pipelines on AWS - Builders Day Israel
CI/CD pipelines on AWS - Builders Day IsraelAmazon Web Services
 
Deploying your first application with Kubernetes
Deploying your first application with KubernetesDeploying your first application with Kubernetes
Deploying your first application with KubernetesOVHcloud
 
DevOps Monitoring and Alerting
DevOps Monitoring and AlertingDevOps Monitoring and Alerting
DevOps Monitoring and AlertingKhairul Zebua
 
AWS Fault Injection Simulator를 통한 실전 카오스 엔지니어링 - 윤석찬 AWS 수석 테크에반젤리스트 / 김신 SW엔...
AWS Fault Injection Simulator를 통한 실전 카오스 엔지니어링 - 윤석찬 AWS 수석 테크에반젤리스트 / 김신 SW엔...AWS Fault Injection Simulator를 통한 실전 카오스 엔지니어링 - 윤석찬 AWS 수석 테크에반젤리스트 / 김신 SW엔...
AWS Fault Injection Simulator를 통한 실전 카오스 엔지니어링 - 윤석찬 AWS 수석 테크에반젤리스트 / 김신 SW엔...Amazon Web Services Korea
 
Bon voyage Docker_Kubernetes
Bon voyage Docker_KubernetesBon voyage Docker_Kubernetes
Bon voyage Docker_Kubernetesssuseraada82
 
From Monolithic to Microservices
From Monolithic to Microservices From Monolithic to Microservices
From Monolithic to Microservices Amazon Web Services
 
K8s on AWS - Introducing Amazon EKS
K8s on AWS - Introducing Amazon EKSK8s on AWS - Introducing Amazon EKS
K8s on AWS - Introducing Amazon EKSAmazon Web Services
 
[AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
 [AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵 [AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
[AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵Amazon Web Services Korea
 
(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk
(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk
(DVO201) Scaling Your Web Applications with AWS Elastic BeanstalkAmazon Web Services
 
CI/CD 101
CI/CD 101CI/CD 101
CI/CD 101djdule
 
CI/CD Best Practices for Your DevOps Journey
CI/CD Best  Practices for Your DevOps JourneyCI/CD Best  Practices for Your DevOps Journey
CI/CD Best Practices for Your DevOps JourneyDevOps.com
 
Intro to containerization
Intro to containerizationIntro to containerization
Intro to containerizationBalint Pato
 

What's hot (20)

Introduction to Amazon EKS
Introduction to Amazon EKSIntroduction to Amazon EKS
Introduction to Amazon EKS
 
__Cloud_CNA_MSA_Service+Data+InferenceMesh 소개-박문기@메가존클라우드-20230320.pptx
__Cloud_CNA_MSA_Service+Data+InferenceMesh 소개-박문기@메가존클라우드-20230320.pptx__Cloud_CNA_MSA_Service+Data+InferenceMesh 소개-박문기@메가존클라우드-20230320.pptx
__Cloud_CNA_MSA_Service+Data+InferenceMesh 소개-박문기@메가존클라우드-20230320.pptx
 
높은 가용성과 성능 향상을 위한 ElastiCache 활용 팁 - 임근택, SendBird :: AWS Summit Seoul 2019
높은 가용성과 성능 향상을 위한 ElastiCache 활용 팁 - 임근택, SendBird :: AWS Summit Seoul 2019 높은 가용성과 성능 향상을 위한 ElastiCache 활용 팁 - 임근택, SendBird :: AWS Summit Seoul 2019
높은 가용성과 성능 향상을 위한 ElastiCache 활용 팁 - 임근택, SendBird :: AWS Summit Seoul 2019
 
mykola marzhan - jenkins on aws spot instance
mykola marzhan - jenkins on aws spot instancemykola marzhan - jenkins on aws spot instance
mykola marzhan - jenkins on aws spot instance
 
Introduction to CI/CD
Introduction to CI/CDIntroduction to CI/CD
Introduction to CI/CD
 
CI/CD pipelines on AWS - Builders Day Israel
CI/CD pipelines on AWS - Builders Day IsraelCI/CD pipelines on AWS - Builders Day Israel
CI/CD pipelines on AWS - Builders Day Israel
 
CICD with Jenkins
CICD with JenkinsCICD with Jenkins
CICD with Jenkins
 
Deploying your first application with Kubernetes
Deploying your first application with KubernetesDeploying your first application with Kubernetes
Deploying your first application with Kubernetes
 
DevOps Monitoring and Alerting
DevOps Monitoring and AlertingDevOps Monitoring and Alerting
DevOps Monitoring and Alerting
 
AWS Fault Injection Simulator를 통한 실전 카오스 엔지니어링 - 윤석찬 AWS 수석 테크에반젤리스트 / 김신 SW엔...
AWS Fault Injection Simulator를 통한 실전 카오스 엔지니어링 - 윤석찬 AWS 수석 테크에반젤리스트 / 김신 SW엔...AWS Fault Injection Simulator를 통한 실전 카오스 엔지니어링 - 윤석찬 AWS 수석 테크에반젤리스트 / 김신 SW엔...
AWS Fault Injection Simulator를 통한 실전 카오스 엔지니어링 - 윤석찬 AWS 수석 테크에반젤리스트 / 김신 SW엔...
 
Bon voyage Docker_Kubernetes
Bon voyage Docker_KubernetesBon voyage Docker_Kubernetes
Bon voyage Docker_Kubernetes
 
JVM++: The Graal VM
JVM++: The Graal VMJVM++: The Graal VM
JVM++: The Graal VM
 
From Monolithic to Microservices
From Monolithic to Microservices From Monolithic to Microservices
From Monolithic to Microservices
 
K8s on AWS - Introducing Amazon EKS
K8s on AWS - Introducing Amazon EKSK8s on AWS - Introducing Amazon EKS
K8s on AWS - Introducing Amazon EKS
 
[AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
 [AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵 [AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
[AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
 
(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk
(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk
(DVO201) Scaling Your Web Applications with AWS Elastic Beanstalk
 
CI/CD 101
CI/CD 101CI/CD 101
CI/CD 101
 
AWS CodeDeploy
AWS CodeDeployAWS CodeDeploy
AWS CodeDeploy
 
CI/CD Best Practices for Your DevOps Journey
CI/CD Best  Practices for Your DevOps JourneyCI/CD Best  Practices for Your DevOps Journey
CI/CD Best Practices for Your DevOps Journey
 
Intro to containerization
Intro to containerizationIntro to containerization
Intro to containerization
 

Similar to SECURING MICROSERVICES WITH JWT

Authenticating Angular Apps with JWT
Authenticating Angular Apps with JWTAuthenticating Angular Apps with JWT
Authenticating Angular Apps with JWTJennifer Estrada
 
Box connector
Box connectorBox connector
Box connectorThang Loi
 
A Detailed Guide to Securing React applications with Keycloak - WalkingTree ...
A Detailed Guide to Securing React applications with Keycloak  - WalkingTree ...A Detailed Guide to Securing React applications with Keycloak  - WalkingTree ...
A Detailed Guide to Securing React applications with Keycloak - WalkingTree ...Ganesh Kumar
 
OpenID 4 Verifiable Credentials + HAIP (Update)
OpenID 4 Verifiable Credentials + HAIP (Update)OpenID 4 Verifiable Credentials + HAIP (Update)
OpenID 4 Verifiable Credentials + HAIP (Update)Torsten Lodderstedt
 
DevConf.CZ 2020 @ Brno, Czech Republic : WebAuthn support for keycloak
DevConf.CZ 2020 @ Brno, Czech Republic : WebAuthn support for keycloakDevConf.CZ 2020 @ Brno, Czech Republic : WebAuthn support for keycloak
DevConf.CZ 2020 @ Brno, Czech Republic : WebAuthn support for keycloakHitachi, Ltd. OSS Solution Center.
 
GSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleGSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleMayank Sharma
 
Microservices Security landscape
Microservices Security landscapeMicroservices Security landscape
Microservices Security landscapeSagara Gunathunga
 
AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"
AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"
AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"Andreas Falk
 
Microservices security - jpmc tech fest 2018
Microservices security - jpmc tech fest 2018Microservices security - jpmc tech fest 2018
Microservices security - jpmc tech fest 2018MOnCloud
 
Configuring kerberos based sso in weblogic
Configuring kerberos based sso in weblogicConfiguring kerberos based sso in weblogic
Configuring kerberos based sso in weblogicHarihara sarma
 
ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2Rodrigo Cândido da Silva
 
2016 pycontw web api authentication
2016 pycontw web api authentication 2016 pycontw web api authentication
2016 pycontw web api authentication Micron Technology
 
Building IAM for OpenStack
Building IAM for OpenStackBuilding IAM for OpenStack
Building IAM for OpenStackSteve Martinelli
 
Lightweight Zero-trust Network Implementation and Transition with Keycloak an...
Lightweight Zero-trust Network Implementation and Transition with Keycloak an...Lightweight Zero-trust Network Implementation and Transition with Keycloak an...
Lightweight Zero-trust Network Implementation and Transition with Keycloak an...Hitachi, Ltd. OSS Solution Center.
 
2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...
2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...
2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...Vladimir Bychkov
 
OAuth with Salesforce - Demystified
OAuth with Salesforce - DemystifiedOAuth with Salesforce - Demystified
OAuth with Salesforce - DemystifiedCalvin Noronha
 
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API ManagerWSO2
 
#5 WSO2 Masterclassitalia - WSO2 Identity Server, un approccio OAUTH2
#5 WSO2 Masterclassitalia - WSO2 Identity Server, un approccio OAUTH2#5 WSO2 Masterclassitalia - WSO2 Identity Server, un approccio OAUTH2
#5 WSO2 Masterclassitalia - WSO2 Identity Server, un approccio OAUTH2Profesia Srl, Lynx Group
 

Similar to SECURING MICROSERVICES WITH JWT (20)

Authenticating Angular Apps with JWT
Authenticating Angular Apps with JWTAuthenticating Angular Apps with JWT
Authenticating Angular Apps with JWT
 
Box connector
Box connectorBox connector
Box connector
 
A Detailed Guide to Securing React applications with Keycloak - WalkingTree ...
A Detailed Guide to Securing React applications with Keycloak  - WalkingTree ...A Detailed Guide to Securing React applications with Keycloak  - WalkingTree ...
A Detailed Guide to Securing React applications with Keycloak - WalkingTree ...
 
OpenID 4 Verifiable Credentials + HAIP (Update)
OpenID 4 Verifiable Credentials + HAIP (Update)OpenID 4 Verifiable Credentials + HAIP (Update)
OpenID 4 Verifiable Credentials + HAIP (Update)
 
DevConf.CZ 2020 @ Brno, Czech Republic : WebAuthn support for keycloak
DevConf.CZ 2020 @ Brno, Czech Republic : WebAuthn support for keycloakDevConf.CZ 2020 @ Brno, Czech Republic : WebAuthn support for keycloak
DevConf.CZ 2020 @ Brno, Czech Republic : WebAuthn support for keycloak
 
GSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleGSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 Module
 
Microservices Security landscape
Microservices Security landscapeMicroservices Security landscape
Microservices Security landscape
 
OpenID for SSI
OpenID for SSIOpenID for SSI
OpenID for SSI
 
AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"
AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"
AllTheTalks.Online 2020: "Basics of OAuth 2.0 and OpenID Connect"
 
Microservices security - jpmc tech fest 2018
Microservices security - jpmc tech fest 2018Microservices security - jpmc tech fest 2018
Microservices security - jpmc tech fest 2018
 
Configuring kerberos based sso in weblogic
Configuring kerberos based sso in weblogicConfiguring kerberos based sso in weblogic
Configuring kerberos based sso in weblogic
 
ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2
 
2016 pycontw web api authentication
2016 pycontw web api authentication 2016 pycontw web api authentication
2016 pycontw web api authentication
 
Building IAM for OpenStack
Building IAM for OpenStackBuilding IAM for OpenStack
Building IAM for OpenStack
 
Lightweight Zero-trust Network Implementation and Transition with Keycloak an...
Lightweight Zero-trust Network Implementation and Transition with Keycloak an...Lightweight Zero-trust Network Implementation and Transition with Keycloak an...
Lightweight Zero-trust Network Implementation and Transition with Keycloak an...
 
1205 bhat pdf-ssl
1205 bhat pdf-ssl1205 bhat pdf-ssl
1205 bhat pdf-ssl
 
2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...
2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...
2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...
 
OAuth with Salesforce - Demystified
OAuth with Salesforce - DemystifiedOAuth with Salesforce - Demystified
OAuth with Salesforce - Demystified
 
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
[WSO2 API Manager Community Call] Mastering JWTs with WSO2 API Manager
 
#5 WSO2 Masterclassitalia - WSO2 Identity Server, un approccio OAUTH2
#5 WSO2 Masterclassitalia - WSO2 Identity Server, un approccio OAUTH2#5 WSO2 Masterclassitalia - WSO2 Identity Server, un approccio OAUTH2
#5 WSO2 Masterclassitalia - WSO2 Identity Server, un approccio OAUTH2
 

Recently uploaded

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 

Recently uploaded (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 

SECURING MICROSERVICES WITH JWT

  • 1. Securing Microservices WSO2 Identity Server Anupam Gogoi - Associate Technical Lead
  • 2. Pre-requisites • JDK 8 • Maven • Eclipse or IntelliJ • WSO2 Identity Server 5.7.0
  • 3. Lab Exercise 1 - Create Microservice Part 1 We are going to create a simple Microservice in Spring Boot. The service contains a resource protected by OAuth2. Part 2 Configure WSO2 Identity Server as OAuth2/OpenID authorization server.
  • 4. Solution Lab Exercise 1 Part 1 Creating a Spring Boot microservice. Code repository https://github.com/anupamgogoi-wso2/wso2-summit
  • 6. Spring Boot Microservice • Visit the site https://start.spring.io/ and create a project with dependencies Web and Security. • Import the project in Eclipse/IntelliJ and add one more dependency by hand in the pom.xml <dependency> <groupId>org.springframework.security.oauth.boot</groupId> <artifactId>spring-security-oauth2-autoconfigure</artifactId> <version>2.0.6.RELEASE</version> </dependency> • Add your logic. • https://github.com/anupamgogoi-wso2/wso2-summit
  • 7. Spring Boot - Configure Auth. Server Note that for client id and client secret you need to use valid username password from WSO2 Identity server.Here i have used default admin username/password.According to this configuration resource server will use OAuth2 introspection API to validate the token. security.oauth2.client.client-id=admin security.oauth2.client.client-secret=admin security.oauth2.client.access-token-uri=https://localhost:9443/oauth2/token security.oauth2.client.user-authorization-uri=https://localhost:9443/oauth2/token/authorize security.oauth2.client.scope=openid security.oauth2.resource.filter-order=3 security.oauth2.resource.user-info-uri=https://localhost:9443/oauth2/userinfo security.oauth2.resource.token-info-uri=https://localhost:9443/oauth2/introspect security.oauth2.resource.prefer-token-info=true
  • 8. Spring Boot - Run The important thing is to pass client truststore details while executing the jar file.Spring security will use SSL connection to talk with Authorization server to validate the access token.The spring boot runtime should be provided with certificate store to find out the authorization server certificate authority and trust it. java -Djavax.net.ssl.trustStore=/Users/anupamgogoi/softwares/wso2/is/wso2is- 5.7.0/repository/resources/security/client-truststore.jks -Djavax.net.ssl.trustStorePassword=wso2carbon -jar /Users/anupamgogoi/git/wso2-summit/spring-oauth2-microservice/target/spring-oauth2-microservice- 1.0.0.jar
  • 9. Solution Lab Exercise 1 Part 2 Configure WSO2 Identity Server as OAuth2 Authorization Server
  • 10. High Level Overview • We will use a simple 3 entity example 1) User, 2) Application server, and 3) Authentication server. • The authentication server will provide the JWT to the user. With the JWT, the user can then safely communicate with the application.
  • 11. Configure WSO2 Identity Server • Log into the IS (admin/admin) • Navigate to Service Providers menu and click add.
  • 12. Add Service Provider - IS Provide Basic Information for the Service Provider. Eg. Service Provider Name: OAUTH2
  • 13. Inbound Authentication Configuration Click Inbound Authentication Configuration and expand OAuth/OpenID Connect Configuration.
  • 14. OAuth/OpenID Connect Configuration Configure OAuth2. Choose Token Issuer as Default (OAuth2). Note that we can choose JWT also. (Next lab)
  • 15. OAuth/OpenID Connect Configuration Once configuration is saved you will be provided with the Client Key and Client Secret.
  • 16. Microservice Resource The Spring Boot microservice contains a resource protected by OAuth2. GET http://localhost:8080/app/products To access this resource, an Access Token must be provided in the Authorization header.
  • 17. Generating Access Token - Postman • Token URI of the Identity Server, https://localhost:9443/oauth2/token • Use password grant_type and provide necessary details. Note that the client_id & client_secret are generated while adding the Service Provider in the IS. • Make sure to send the following header, Content-Type: application/x-www-form-urlencoded
  • 18. Generating Access Token - CURL curl -u <CLINET_ID>:<CLIENT_SECRET> -k -d "grant_type=password&username=admin&password=admin" -H "Content-Type:application/x-www-form-urlencoded" https://localhost:9443/oauth2/token Invoke Microservice curl -k http://localhost:8080/app/products -H "Authorization: Bearer <<ACCESS_TOKEN>>
  • 19. Lab Exercise 2 Using JWT to access the protected resource of the microservice.
  • 20. Solution - Lab Exercise 2 We are going to use the same Spring Boot microservice with the same resource. Only thing we will need to change is in the Identity Server to generate JWT.
  • 21. Configure identity.xml - IS ● Open the <IS_HOME>/repository/conf/identity/identity.xml file and set the <Enabled> element (found under the <OAuth>,<AuthorizationContextTokenGeneration> elements) to true as shown in the code block below. ● Add the following property under <OAUTH> section to use the JWT Token Builder instead of the default Token Builder. <IdentityOAuthTokenGenerator>org.wso2.carbon.identity.oauth2.token.JWTTokenIssuer</IdentityOAuthTokenGenerator>
  • 22. Configure identity.xml - IS • Configure the “audiences” parameter as mentioned below so that the token includes information about the intended audiences who can use the generated token for authenticating the user. <EnableAudiences>true</EnableAudiences> <Audiences> <Audience>${carbon.protocol}://${carbon.host}:${carbon.management.port}/oauth2/token</Audience> </Audiences> • Configure a meaningful value to the <IDTokenIssuerID> parameter in the identity.xml file <IDTokenIssuerID>my-jwt-token</IDTokenIssuerID> • Start the IS sh wso2server.sh
  • 23. Configure Identity Provider - IS Go into Identity-> Identity Providers and click on “Add”.
  • 24. Configure Identity Provider - IS Identity Provider Name—This needs to be the same value as the <IDTokenIssuerID> value you configure at the identity.xml file since this value will be the issuer ID of the JWT token. Here the value is given as “apim-idp” to match the above mentioned parameter. Identity Provider Public Certificate—Here you need to upload the public certificate of the WSO2 Identity Server in a pem file format. The Identity Provider Public Certificate is the public certificate belonging to the identity provider. Uploading this is necessary to authenticate the response from the identity provider. This can be any certificate. Since we are using WSO2 Identity Server as the IDP we can generate the certificate using the below mentioned commands.
  • 25. Create/Import Certificate • Open your Command Line interface, go to the <IS_HOME>/repository/resources/security/directory. Run the following command. keytool -export -alias wso2carbon -file wso2.crt -keystore wso2carbon.jks -storepass wso2carbon Click Choose File and navigate to this location in order to select and upload this file. • Alias—You need to give the clientID (client key) of the service provider which you will configure in the WSO2 Identity Server here. This will be checked when verifying the JWT token.
  • 26. OAuth/OpenID Connect Configuration • Create a new Service Provider e.g JWT • Choose any valid Url in the Callback Url field. • Choose Token Issuer as JWT.
  • 27. Get JWT & Invoke Service You need to first get a JWT token from the WSO2 identity server by using the token endpoint with the password grant type. You can use the below mentioned curl command to get a JWT token, curl -u <CLIENT_ID>:<CLIENT_SECRET> -k -d "grant_type=password&username=admin&password=admin" -H "Content-Type:application/x-www-form-urlencoded" https://localhost:9443/oauth2/token Use the token in Authorization header in the request to access the protected resource of the microservice, curl -k http://localhost:8080/app/products -H "Authorization: Bearer <<JWT_TOKEN>>"
  • 28.