DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Software Design and Architecture
  3. Security
  4. Authenticating Web Users With OpenID and JWT

Authenticating Web Users With OpenID and JWT

Want to learn more about authentication web users with OpenID and JSON web tokens?

Niklas Heidloff user avatar by
Niklas Heidloff
CORE ·
Apr. 16, 19 · Tutorial
Like (4)
Save
Tweet
Share
12.90K Views

Join the DZone community and get the full member experience.

Join For Free

as some of my readers will know, i’m working on a cloud-native-starter repo that demonstrates how to start building cloud-native applications with java ee and istio. one of the required core features for most applications is authentication and authorization.

openid connect and jwt

in order to authenticate and authorize users, i’ve chosen the standard openid connect 1.0 and oauth 2.0, which can be used with many existing identify providers. in the context of enterprise applications, you want to leverage existing organization directories. ibm app id , for example, acts as an identity provider or identity provider proxy. for simple tests, you can define test users in a cloud directory. for production usage, app id can be configured to work against third-party providers such as active directory federation services via saml.

identify providers also come with their own login pages, which means that you, as a developer, don’t have to implement yet another login page with both username and password fields, and enterprise users get a consistent way to log in. with app id, this login page can easily be customized.

the other nice thing about openid connect for developers is that you don’t have to understand the internals of the different identity providers but can use standardized and easy apis. as a response of successful oauth dances, you get access tokens and user tokens as json web token (jwt).

sample implementation

in order to authenticate users, i use ibm app id with a test user in a cloud directory. i’ve implemented another service, called ‘authentication’, via node.js and the npm module ‘ openid-client ‘. the vue.js application invokes a ‘login’ endpoint of this service. the authentication service triggers the oauth dance and returns the tokens to the web application.

here is my sample application. the three components that are run for authentication are:

1. app id

2. authentication

3. web app

image title

after successful logins, the vue.js web application retrieves the access token and stores it together with the username and email address in the vuex store.

image title

this animated gif shows the authentication flow.

run the sample yourself

if you want to run this sample, follow the instructions in the repo.

essentially, when you have an ibm cloud account, and when you have minikube with istio running locally, all you need to do is to invoke the following commands:

$ git clone https://github.com/nheidloff/cloud-native-starter.git
$ ibm-scripts/create-app-id.sh
$ scripts/deploy-web-api-java-jee.sh
$ scripts/deploy-authentication-nodejs.sh
$ scripts/deploy-web-app-vuejs-authentication.sh
$ scripts/deploy-istio-ingress-v1.sh
$ scripts/show-urls.sh


note: since this is a starter repo, i’m using http only at this point. for production usage, you should leverage secure connections.

over the next days, i’ll blog about how to use these tokens to invoke protected endpoints of the ‘web-api’ service and how to access the tokens in java applications to authorize users.

stay tuned!

Web Service OpenID application JWT (JSON Web Token) app authentication

Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Getting a Private SSL Certificate Free of Cost
  • What Are the Different Types of API Testing?
  • A Gentle Introduction to Kubernetes
  • 10 Most Popular Frameworks for Building RESTful APIs

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: