+ - 0:00:00
Notes for current slide
Notes for next slide

Introduction to OAuth 2.0
and OpenID Connect

oauth logo

1 / 35

Day 1

2 / 35

Day 1

(1) Intro (~ 10 minutes)
  • About Me
  • Objectives
2 / 35

Day 1

(1) Intro (~ 10 minutes)
  • About Me
  • Objectives
(2) Theory (~ 2 hours)
  • Authentication vs Authorization
  • OAuth
    • What is OAuth?
    • Terminology
    • Authorization Code flow
    • Grant types
    • History of OAuth
2 / 35

Day 1

(1) Intro (~ 10 minutes)
  • About Me
  • Objectives
(2) Theory (~ 2 hours)
  • Authentication vs Authorization
  • OAuth
    • What is OAuth?
    • Terminology
    • Authorization Code flow
    • Grant types
    • History of OAuth
(3) Practice (~ 5 hours)
  • Developing an OAuth 2.0 Authorization Server with Node
2 / 35

Day 2

3 / 35

Day 2

(1) Theory (~ 1 hour)
  • Day 1 Review
  • OpenID Connect
    • What is OpenID Connect?
    • How does OpenID Connect work with OAuth 2.0?
    • JSON Web Tokens (JWT)
3 / 35

Day 2

(1) Theory (~ 1 hour)
  • Day 1 Review
  • OpenID Connect
    • What is OpenID Connect?
    • How does OpenID Connect work with OAuth 2.0?
    • JSON Web Tokens (JWT)
(2) Practice (~ 5 hours)
  • Adding OpenID Connect to the OAuth 2.0 Server
  • Developing a Client application with Node and Express
3 / 35

Day 2

(1) Theory (~ 1 hour)
  • Day 1 Review
  • OpenID Connect
    • What is OpenID Connect?
    • How does OpenID Connect work with OAuth 2.0?
    • JSON Web Tokens (JWT)
(2) Practice (~ 5 hours)
  • Adding OpenID Connect to the OAuth 2.0 Server
  • Developing a Client application with Node and Express
(3) Theory (~ 1 hour)
  • Final Review
  • Next Steps
3 / 35

Intro

4 / 35

About Michael

$ whoami
michael.herman

me

5 / 35

About Michael

$ whoami
michael.herman

me

Senior Software Engineer from Denver, CO

  1. Full-stack + DevOps Contractor
  2. TestDriven.io

testdriven.io

5 / 35

About Michael

$ whoami
michael.herman

me

Senior Software Engineer from Denver, CO

  1. Full-stack + DevOps Contractor
  2. TestDriven.io

testdriven.io

Also

  1. Founder and Organizer of Denver Node.js Meetup Group
  2. Former Lead Instructor at Galvanize
  3. Co-founder/author of Real Python
  4. 😍 - tech writing/education, open source, financial models, radiohead
5 / 35

Objectives

6 / 35

Objectives

By the end of this training, you will be able to:

6 / 35

Objectives

By the end of this training, you will be able to:

  1. Describe the difference between authentication and authorization
6 / 35

Objectives

By the end of this training, you will be able to:

  1. Describe the difference between authentication and authorization

  2. Explain what OAuth 2.0 is and how it differs from OAuth 1.0

6 / 35

Objectives

By the end of this training, you will be able to:

  1. Describe the difference between authentication and authorization

  2. Explain what OAuth 2.0 is and how it differs from OAuth 1.0

  3. Describe the various OAuth 2.0 grant types and when it's appropriate to use each

6 / 35

Objectives

By the end of this training, you will be able to:

  1. Describe the difference between authentication and authorization

  2. Explain what OAuth 2.0 is and how it differs from OAuth 1.0

  3. Describe the various OAuth 2.0 grant types and when it's appropriate to use each

  4. Implement an OAuth 2.0 server with Node

6 / 35

Objectives

By the end of this training, you will be able to:

  1. Describe the difference between authentication and authorization

  2. Explain what OAuth 2.0 is and how it differs from OAuth 1.0

  3. Describe the various OAuth 2.0 grant types and when it's appropriate to use each

  4. Implement an OAuth 2.0 server with Node

  5. Explain what OpenID Connect is and how it works with OAuth 2.0

6 / 35

Objectives

By the end of this training, you will be able to:

  1. Describe the difference between authentication and authorization

  2. Explain what OAuth 2.0 is and how it differs from OAuth 1.0

  3. Describe the various OAuth 2.0 grant types and when it's appropriate to use each

  4. Implement an OAuth 2.0 server with Node

  5. Explain what OpenID Connect is and how it works with OAuth 2.0

  6. Implement OpenID Connect with Node

6 / 35

Objectives

By the end of this training, you will be able to:

  1. Describe the difference between authentication and authorization

  2. Explain what OAuth 2.0 is and how it differs from OAuth 1.0

  3. Describe the various OAuth 2.0 grant types and when it's appropriate to use each

  4. Implement an OAuth 2.0 server with Node

  5. Explain what OpenID Connect is and how it works with OAuth 2.0

  6. Implement OpenID Connect with Node

  7. Develop a Client app to interact with an OAuth 2.0 and OpenID Connect server

6 / 35

Theory

7 / 35

Authentication vs Authorization

8 / 35

Authentication vs Authorization

"Who are you and what are you allowed to do?"

8 / 35

Authentication vs Authorization

"Who are you and what are you allowed to do?"

Authentication

  • Verifying that someone is who they claim to be.
  • Who are you?
8 / 35

Authentication vs Authorization

"Who are you and what are you allowed to do?"

Authentication

  • Verifying that someone is who they claim to be.
  • Who are you?

Authorization

  • Verifying which resources a user can access and what they are allowed to do with those resources.
  • What are you allowed to do?
8 / 35

Authentication vs Authorization

"Who are you and what are you allowed to do?"

Authentication

  • Verifying that someone is who they claim to be.
  • Who are you?

Authorization

  • Verifying which resources a user can access and what they are allowed to do with those resources.
  • What are you allowed to do?

Single Sign-On (SSO)

  • Allows a user to enter one set of credentials in order to access multiple applications.

sign up with google

8 / 35

What is OAuth?

9 / 35

What is OAuth?

Oauth is an open standard for authorization.

"An open protocol to allow secure authorization in a simple and standard method from web, mobile and desktop applications."

9 / 35

What is OAuth?

Oauth is an open standard for authorization.

"An open protocol to allow secure authorization in a simple and standard method from web, mobile and desktop applications."

It's all about delegation:

9 / 35

What is OAuth?

Oauth is an open standard for authorization.

"An open protocol to allow secure authorization in a simple and standard method from web, mobile and desktop applications."

It's all about delegation:

  1. The Client application accesses resources, from a Resource Server, on behalf of the User.
  2. The User does not have to share their credentials with the Client.
9 / 35

What is OAuth?

Oauth is an open standard for authorization.

"An open protocol to allow secure authorization in a simple and standard method from web, mobile and desktop applications."

It's all about delegation:

  1. The Client application accesses resources, from a Resource Server, on behalf of the User.
  2. The User does not have to share their credentials with the Client.


Compared to OAuth 1.0, OAuth 2.0:

  • Is slightly simpler to implement
  • Adds time to live (TTL) to the Access Tokens
  • Supports mobile and desktop apps
  • No longer requires Client applications to have cryptography
9 / 35

Terminology

10 / 35

Terminology

Term Definition
Resource Owner (aka User) End user who authorizes an application to access their account
Client (aka Consumer) Application that accesses protected resources on behalf of the user
Authorization Server Server which grants Access Tokens after the user authorizes the application
Resource Server Restricted resource / API
Access Token Token used to access restricted resources
Authorization Code Intermediate token returned to the client, after the user authorization step, which the client exchanges it for an Access Token
Grant Method of acquiring an Access Token
10 / 35

Grant Types

11 / 35

Grant Types

Grant Type Use Case Link
Authorization Code Server-side web apps 4.1
Implicit Single Page Apps (SPAs) 4.2
Resource Owner Credentials (Password) Trusted first party clients 4.3
Client Credentials Machine-to-machine 4.4
11 / 35

Grant Types

Grant Type Use Case Link
Authorization Code Server-side web apps 4.1
Implicit Single Page Apps (SPAs) 4.2
Resource Owner Credentials (Password) Trusted first party clients 4.3
Client Credentials Machine-to-machine 4.4

Questions

11 / 35

Grant Types

Grant Type Use Case Link
Authorization Code Server-side web apps 4.1
Implicit Single Page Apps (SPAs) 4.2
Resource Owner Credentials (Password) Trusted first party clients 4.3
Client Credentials Machine-to-machine 4.4

Questions

11 / 35

Grant Types

Grant Type Use Case Link
Authorization Code Server-side web apps 4.1
Implicit Single Page Apps (SPAs) 4.2
Resource Owner Credentials (Password) Trusted first party clients 4.3
Client Credentials Machine-to-machine 4.4

Questions

  • Which grant should you use? Decision tree

  • First vs third party client?

    • First party clients are clients that you trust. For example, Twitter probably trusts the Twitter iPhone app since they own it.
    • Third party clients are clients that you don't trust.
11 / 35

Grant Types

Grant Type Use Case Link
Authorization Code Server-side web apps 4.1
Implicit Single Page Apps (SPAs) 4.2
Resource Owner Credentials (Password) Trusted first party clients 4.3
Client Credentials Machine-to-machine 4.4

Questions

  • Which grant should you use? Decision tree

  • First vs third party client?

    • First party clients are clients that you trust. For example, Twitter probably trusts the Twitter iPhone app since they own it.
    • Third party clients are clients that you don't trust.
  • Access Token Owner? Do you not need the user's permission to access the restricted resources?
11 / 35

Grant Types

Grant Type Use Case Link
Authorization Code Server-side web apps 4.1
Implicit Single Page Apps (SPAs) 4.2
Resource Owner Credentials (Password) Trusted first party clients 4.3
Client Credentials Machine-to-machine 4.4

Questions

  • Which grant should you use? Decision tree

  • First vs third party client?

    • First party clients are clients that you trust. For example, Twitter probably trusts the Twitter iPhone app since they own it.
    • Third party clients are clients that you don't trust.
  • Access Token Owner? Do you not need the user's permission to access the restricted resources?

Source: A Guide to OAuth 2.0 Grants

11 / 35

Authorization Code Flow

12 / 35

Authorization Code Flow


[Step 1] Client redirects the Resource Owner to the Authorization Server

oauth flow step 1

12 / 35

Authorization Code Flow


[Step 1] Client redirects the Resource Owner to the Authorization Server

oauth flow step 1


[Step 2] Resource Owner grants authorization

[Step 3] Authorization Server redirects the Resource Owner back to the Client with an Authorization Code

oauth flow step 2 and 3

12 / 35

Authorization Code Flow (continued...)

13 / 35

Authorization Code Flow (continued...)

[Step 4] Client exchanges Authorization Code for Access Token

oauth flow step 4

13 / 35

Authorization Code Flow (continued...)

[Step 4] Client exchanges Authorization Code for Access Token

oauth flow step 4


[Step 5] Authorization Server grants Access Token

oauth flow step 5

13 / 35

Authorization Code Flow (continued...)

14 / 35

Authorization Code Flow (continued...)


[Step 6] Client uses the Access Token to access protected resources, from the Resource Server, on behalf of the Resource Owner

oauth flow

14 / 35

Authorization Code Flow (continued...)


[Step 6] Client uses the Access Token to access protected resources, from the Resource Server, on behalf of the Resource Owner

oauth flow


What's different about this flow for the other grant types—Implicit, Resource Owner Credentials, Client Credentials? Understanding OAuth2

14 / 35

History of OAuth

15 / 35

History of OAuth

Before OAuth

15 / 35

History of OAuth

Before OAuth

The User would provide their credentials directly to the Client app.

15 / 35

History of OAuth

Before OAuth

The User would provide their credentials directly to the Client app.

Problems
  1. Client stores User's password (one more application with your password)
  2. Client gets complete access to the User's account (scope)
  3. User cannot revoke access to the Client unless they reset their password
15 / 35

History of OAuth

Before OAuth

The User would provide their credentials directly to the Client app.

Problems
  1. Client stores User's password (one more application with your password)
  2. Client gets complete access to the User's account (scope)
  3. User cannot revoke access to the Client unless they reset their password

Oauth 1.0

15 / 35

History of OAuth

Before OAuth

The User would provide their credentials directly to the Client app.

Problems
  1. Client stores User's password (one more application with your password)
  2. Client gets complete access to the User's account (scope)
  3. User cannot revoke access to the Client unless they reset their password

Oauth 1.0

Introduced in December 2007 to prevent the Client application from having to directly handle the User's credentials.

15 / 35

History of OAuth

Before OAuth

The User would provide their credentials directly to the Client app.

Problems
  1. Client stores User's password (one more application with your password)
  2. Client gets complete access to the User's account (scope)
  3. User cannot revoke access to the Client unless they reset their password

Oauth 1.0

Introduced in December 2007 to prevent the Client application from having to directly handle the User's credentials.

Problems
  1. Difficult to implement
  2. Complex cryptographic requirements
  3. Poor support for native desktop and mobile apps
15 / 35

History of OAuth (continued...)

16 / 35

History of OAuth (continued...)

OAuth 2.0

First came out in April 2010.

16 / 35

History of OAuth (continued...)

OAuth 2.0

First came out in April 2010.

Problems
  1. Still difficult to implement
  2. Difficult for the User to update the scope
  3. Security concerns
16 / 35

History of OAuth (continued...)

OAuth 2.0

First came out in April 2010.

Problems
  1. Still difficult to implement
  2. Difficult for the User to update the scope
  3. Security concerns


16 / 35

Check for Understanding

17 / 35

Check for Understanding

  • What's the difference between authentication and authorization?
17 / 35

Check for Understanding

  • What's the difference between authentication and authorization?

  • What is OAuth?

17 / 35

Check for Understanding

  • What's the difference between authentication and authorization?

  • What is OAuth?

  • Describe the various OAuth 2.0 grant types

17 / 35

Check for Understanding

  • What's the difference between authentication and authorization?

  • What is OAuth?

  • Describe the various OAuth 2.0 grant types

  • How does the grant type affect the OAuth 2.0 authorization flow?



🤔

17 / 35

Practice

18 / 35

What are we building?

19 / 35

What are we building?

Day 1

  • We'll build an OAuth 2.0 Authorization Server with Node, Express, and Postgres that uses the Authorization Code grant type.

node logo

19 / 35

What are we building?

Day 1

  • We'll build an OAuth 2.0 Authorization Server with Node, Express, and Postgres that uses the Authorization Code grant type.

node logo

Day 2

  • We'll add OpenID Connect to the existing server.
  • Then, we'll create a separate Client application that can authorize against the Authorization Server.
19 / 35

What are we building?

Day 1

  • We'll build an OAuth 2.0 Authorization Server with Node, Express, and Postgres that uses the Authorization Code grant type.

node logo

Day 2

  • We'll add OpenID Connect to the existing server.
  • Then, we'll create a separate Client application that can authorize against the Authorization Server.

Prerequisites

You should:

  1. Have Node (v11.12.0), NPM (v6.7.0), Postgres (v9.6+), and git installed.
  2. Be familiar with Javascript syntax and fundamentals.
  3. Have a basic understanding of the Unix command line.
  4. Be able to build a RESTful API with Node, Express, and Postgres.
19 / 35

Getting Started

20 / 35

Getting Started

Clone down the node-oauth-openid repo and check out the base tag:

$ git clone https://github.com/mjhea0/node-oauth-openid
$ git checkout -b base
20 / 35

Getting Started

Clone down the node-oauth-openid repo and check out the base tag:

$ git clone https://github.com/mjhea0/node-oauth-openid
$ git checkout -b base

Install the dependencies:

$ npm install
20 / 35

Getting Started

Clone down the node-oauth-openid repo and check out the base tag:

$ git clone https://github.com/mjhea0/node-oauth-openid
$ git checkout -b base

Install the dependencies:

$ npm install

Run the server:

$ npm start

Ensure the server is up and running at http://localhost:3001/ and http://localhost:3001/ping.

20 / 35

Getting Started

Clone down the node-oauth-openid repo and check out the base tag:

$ git clone https://github.com/mjhea0/node-oauth-openid
$ git checkout -b base

Install the dependencies:

$ npm install

Run the server:

$ npm start

Ensure the server is up and running at http://localhost:3001/ and http://localhost:3001/ping.


Let's review app.js together...

20 / 35

Structure

21 / 35

Structure

Authorize Endpoints

21 / 35

Structure

Authorize Endpoints

/oauth/authorize - GET

  1. Query params - Grant type, client ID, redirect URI, state
  2. Force the user to log in
  3. Ensure the client exists
  4. Redirect user to the dialog endpoint
21 / 35

Structure

Authorize Endpoints

/oauth/authorize - GET

  1. Query params - Grant type, client ID, redirect URI, state
  2. Force the user to log in
  3. Ensure the client exists
  4. Redirect user to the dialog endpoint

/oauth/authorize/dialog - GET

  1. Display authorize dialog
21 / 35

Structure

Authorize Endpoints

/oauth/authorize - GET

  1. Query params - Grant type, client ID, redirect URI, state
  2. Force the user to log in
  3. Ensure the client exists
  4. Redirect user to the dialog endpoint

/oauth/authorize/dialog - GET

  1. Display authorize dialog

/oauth/authorize/dialog - POST

  1. If authorized, generate Authorization Code and redirect user to the redirect URI with the Authorization Code and state
  2. If not authorized, send back an error
21 / 35

Structure (continued...)

22 / 35

Structure (continued...)

Token Endpoint

22 / 35

Structure (continued...)

Token Endpoint

/oauth/token - POST

  1. Payload - Authorization Code
  2. Ensure the Authorization Code has not expired or been consumed
  3. Mark Authorization Code as consumed
  4. Generate an Access Token (and an optional Refresh Token)
  5. Respond via JSON with the Access Token, optional Refresh Token, and how long the Access Token is good for

User Info Endpoint

22 / 35

Structure (continued...)

Token Endpoint

/oauth/token - POST

  1. Payload - Authorization Code
  2. Ensure the Authorization Code has not expired or been consumed
  3. Mark Authorization Code as consumed
  4. Generate an Access Token (and an optional Refresh Token)
  5. Respond via JSON with the Access Token, optional Refresh Token, and how long the Access Token is good for

User Info Endpoint

/oauth/userinfo - GET

  1. Header - Access Token (Authorization: Bearer <token>)
  2. Ensure the Authorization Code is valid
  3. If valid, send back true
  4. If not valid, send back false
22 / 35

Structure (continued...)

23 / 35

Structure (continued...)

Models

23 / 35

Structure (continued...)

Models

  1. user - user ID, email, client ID
  2. client - client ID, name, redirect URI
  3. authCode - code, created at, consumed, user ID
  4. accessToken - token, created at, expires in, token type (e.g., bearer), user ID, refresh token (optional)
23 / 35

Structure (continued...)

Models

  1. user - user ID, email, client ID
  2. client - client ID, name, redirect URI
  3. authCode - code, created at, consumed, user ID
  4. accessToken - token, created at, expires in, token type (e.g., bearer), user ID, refresh token (optional)

Bearer Token

23 / 35

Structure (continued...)

Models

  1. user - user ID, email, client ID
  2. client - client ID, name, redirect URI
  3. authCode - code, created at, consumed, user ID
  4. accessToken - token, created at, expires in, token type (e.g., bearer), user ID, refresh token (optional)

Bearer Token

Bearer Tokens are probably the most popular type of Access Token. They must be unique, nonsequential, and nonguessable.

23 / 35

Structure (continued...)

Models

  1. user - user ID, email, client ID
  2. client - client ID, name, redirect URI
  3. authCode - code, created at, consumed, user ID
  4. accessToken - token, created at, expires in, token type (e.g., bearer), user ID, refresh token (optional)

Bearer Token

Bearer Tokens are probably the most popular type of Access Token. They must be unique, nonsequential, and nonguessable.

Using Bearer Tokens:

  1. Authorization Request Header Field: Authorization: Bearer 4ae6ce68-4c59-4313-94e2-fcc2932cf5ca
  2. Form-Encoded Body Parameter: Content-Type: application/x-www-form-urlencoded, access_token=mF_9.B5f-4.1JqM
  3. URI Query Parameter: resource?access_token=mF_9.B5f-4.1JqM
23 / 35

Implementation

24 / 35

Implementation

So, we need to implement the following:

  1. Models: user, client, authCode, accessToken
  2. Routes: /oauth/authorize (GET), /oauth/authorize/dialog (GET and POST), /oauth/token (POST), /oauth/userinfo (GET)
24 / 35

Implementation

So, we need to implement the following:

  1. Models: user, client, authCode, accessToken
  2. Routes: /oauth/authorize (GET), /oauth/authorize/dialog (GET and POST), /oauth/token (POST), /oauth/userinfo (GET)

Let's skip user log in for now and get something working. What else can we punt in order to get a working prototype up and running?

24 / 35

Implementation

So, we need to implement the following:

  1. Models: user, client, authCode, accessToken
  2. Routes: /oauth/authorize (GET), /oauth/authorize/dialog (GET and POST), /oauth/token (POST), /oauth/userinfo (GET)

Let's skip user log in for now and get something working. What else can we punt in order to get a working prototype up and running?

Where do we begin?

24 / 35

Homework

  1. Finish the Node Authentication Server
  2. Read User Authentication with OAuth 2.0 and Understanding OAuth 2.0 and OpenID Connect
25 / 35

Theory

26 / 35

Day 1 Review

27 / 35

Day 1 Review

  • What's the difference between authentication and authorization?
27 / 35

Day 1 Review

  • What's the difference between authentication and authorization?

  • What is OAuth?

27 / 35

Day 1 Review

  • What's the difference between authentication and authorization?

  • What is OAuth?

  • Describe the various OAuth 2.0 grant types

27 / 35

Day 1 Review

  • What's the difference between authentication and authorization?

  • What is OAuth?

  • Describe the various OAuth 2.0 grant types

  • How does the grant type affect the OAuth 2.0 authorization flow?



🤔

27 / 35

What is OpenID Connect?

28 / 35

What is OpenID Connect?

OpenID Connect (or OIDC), the latest version of OpenID, is a standard for authentication, issued by the OpenID Foundation in February 2014.

28 / 35

What is OpenID Connect?

OpenID Connect (or OIDC), the latest version of OpenID, is a standard for authentication, issued by the OpenID Foundation in February 2014.

How does OpenID Connect work with OAuth 2.0?

28 / 35

What is OpenID Connect?

OpenID Connect (or OIDC), the latest version of OpenID, is a standard for authentication, issued by the OpenID Foundation in February 2014.

How does OpenID Connect work with OAuth 2.0?

  • OpenID Connect extends OAuth 2.0, adding an extra layer for handling user authentication. It's a superset of OAuth 2.0.
28 / 35

What is OpenID Connect?

OpenID Connect (or OIDC), the latest version of OpenID, is a standard for authentication, issued by the OpenID Foundation in February 2014.

How does OpenID Connect work with OAuth 2.0?

  • OpenID Connect extends OAuth 2.0, adding an extra layer for handling user authentication. It's a superset of OAuth 2.0.

  • With OpenID Connect, the token endpoint returns an ID Token instead of an Access Token.

28 / 35

What is OpenID Connect?

OpenID Connect (or OIDC), the latest version of OpenID, is a standard for authentication, issued by the OpenID Foundation in February 2014.

How does OpenID Connect work with OAuth 2.0?

  • OpenID Connect extends OAuth 2.0, adding an extra layer for handling user authentication. It's a superset of OAuth 2.0.

  • With OpenID Connect, the token endpoint returns an ID Token instead of an Access Token.

  • The ID Token is a JSON Web Token that contains information about the authenticated user.

28 / 35

JSON Web Tokens (JWT)

29 / 35

JSON Web Tokens (JWT)

A JSON Web Token (or JWT) is a JSON-based standard for securely transmitting information. They can signed (JWS) or encrypted (JWE).

29 / 35

JSON Web Tokens (JWT)

A JSON Web Token (or JWT) is a JSON-based standard for securely transmitting information. They can signed (JWS) or encrypted (JWE).

Benefits
  • Stateless: Since tokens contain the required info to verify a user's identity, scaling is easier as you do not have to maintain a session store.
  • Single Sign On: After a token is generated, you can have your users access a variety of resources without having to re-authenticate them.
29 / 35

JSON Web Tokens (JWT)

A JSON Web Token (or JWT) is a JSON-based standard for securely transmitting information. They can signed (JWS) or encrypted (JWE).

Benefits
  • Stateless: Since tokens contain the required info to verify a user's identity, scaling is easier as you do not have to maintain a session store.
  • Single Sign On: After a token is generated, you can have your users access a variety of resources without having to re-authenticate them.
Drawbacks
  • Cross-site Scripting (XSS) attacks: Storing tokens in either local or session storage can lead to XSS attacks. Because of this, it's a good idea to store them in a cookie with httpOnly and secure flags.
29 / 35

JSON Web Tokens (JWT)

A JSON Web Token (or JWT) is a JSON-based standard for securely transmitting information. They can signed (JWS) or encrypted (JWE).

Benefits
  • Stateless: Since tokens contain the required info to verify a user's identity, scaling is easier as you do not have to maintain a session store.
  • Single Sign On: After a token is generated, you can have your users access a variety of resources without having to re-authenticate them.
Drawbacks
  • Cross-site Scripting (XSS) attacks: Storing tokens in either local or session storage can lead to XSS attacks. Because of this, it's a good idea to store them in a cookie with httpOnly and secure flags.
29 / 35

Practice

30 / 35

Adding OpenID

Steps

  • Add scope to the /authorize endpoint
31 / 35

Adding OpenID

Steps

  • Add scope to the /authorize endpoint

  • Create (via jsonwebtoken) then return an ID Token in the /token endpoint

31 / 35

Adding OpenID

Steps

  • Add scope to the /authorize endpoint

  • Create (via jsonwebtoken) then return an ID Token in the /token endpoint

  • Modify the /userinfo to decode the ID Token and return user info

31 / 35

Adding OpenID

Steps

  • Add scope to the /authorize endpoint

  • Create (via jsonwebtoken) then return an ID Token in the /token endpoint

  • Modify the /userinfo to decode the ID Token and return user info

Questions

31 / 35

Adding OpenID

Steps

  • Add scope to the /authorize endpoint

  • Create (via jsonwebtoken) then return an ID Token in the /token endpoint

  • Modify the /userinfo to decode the ID Token and return user info

Questions

31 / 35

Adding OpenID

Steps

  • Add scope to the /authorize endpoint

  • Create (via jsonwebtoken) then return an ID Token in the /token endpoint

  • Modify the /userinfo to decode the ID Token and return user info

Questions

31 / 35

Adding OpenID

Steps

  • Add scope to the /authorize endpoint

  • Create (via jsonwebtoken) then return an ID Token in the /token endpoint

  • Modify the /userinfo to decode the ID Token and return user info

Questions

Security Recommendations

  • Always use HTTPS!
31 / 35

Adding OpenID

Steps

  • Add scope to the /authorize endpoint

  • Create (via jsonwebtoken) then return an ID Token in the /token endpoint

  • Modify the /userinfo to decode the ID Token and return user info

Questions

Security Recommendations

  • Always use HTTPS!

  • Issue short lived bearer tokens

31 / 35

Adding OpenID

Steps

  • Add scope to the /authorize endpoint

  • Create (via jsonwebtoken) then return an ID Token in the /token endpoint

  • Modify the /userinfo to decode the ID Token and return user info

Questions

Security Recommendations

  • Always use HTTPS!

  • Issue short lived bearer tokens

  • Don't pass bearer token in page URLs

31 / 35

Client Application

32 / 35

Client Application

Let's spin up a new Express application to serve as the Client.

32 / 35

Client Application

Let's spin up a new Express application to serve as the Client.

Functionality

  • Display "Authorize" button on page load to /
32 / 35

Client Application

Let's spin up a new Express application to serve as the Client.

Functionality

  • Display "Authorize" button on page load to /

  • On button click, redirect User (with Grant type, client ID, redirect URI, Scope, and State) to the Authorization Server's /oauth/authorize endpoint

32 / 35

Client Application

Let's spin up a new Express application to serve as the Client.

Functionality

  • Display "Authorize" button on page load to /

  • On button click, redirect User (with Grant type, client ID, redirect URI, Scope, and State) to the Authorization Server's /oauth/authorize endpoint

  • If the User authorization is successful, the User is redirect back to the Client, to the redirect URI, with the Authorization Code and State

32 / 35

Client Application

Let's spin up a new Express application to serve as the Client.

Functionality

  • Display "Authorize" button on page load to /

  • On button click, redirect User (with Grant type, client ID, redirect URI, Scope, and State) to the Authorization Server's /oauth/authorize endpoint

  • If the User authorization is successful, the User is redirect back to the Client, to the redirect URI, with the Authorization Code and State

  • With the Authorization Code in hand, request Access Token

32 / 35

Client Application

Let's spin up a new Express application to serve as the Client.

Functionality

  • Display "Authorize" button on page load to /

  • On button click, redirect User (with Grant type, client ID, redirect URI, Scope, and State) to the Authorization Server's /oauth/authorize endpoint

  • If the User authorization is successful, the User is redirect back to the Client, to the redirect URI, with the Authorization Code and State

  • With the Authorization Code in hand, request Access Token

  • If the Authorization Code is valid, an ID Token is sent back

32 / 35

Client Application

Let's spin up a new Express application to serve as the Client.

Functionality

  • Display "Authorize" button on page load to /

  • On button click, redirect User (with Grant type, client ID, redirect URI, Scope, and State) to the Authorization Server's /oauth/authorize endpoint

  • If the User authorization is successful, the User is redirect back to the Client, to the redirect URI, with the Authorization Code and State

  • With the Authorization Code in hand, request Access Token

  • If the Authorization Code is valid, an ID Token is sent back

  • Store the ID token

32 / 35

Client Application

Let's spin up a new Express application to serve as the Client.

Functionality

  • Display "Authorize" button on page load to /

  • On button click, redirect User (with Grant type, client ID, redirect URI, Scope, and State) to the Authorization Server's /oauth/authorize endpoint

  • If the User authorization is successful, the User is redirect back to the Client, to the redirect URI, with the Authorization Code and State

  • With the Authorization Code in hand, request Access Token

  • If the Authorization Code is valid, an ID Token is sent back

  • Store the ID token

  • On requests to restricted resources, send the ID Token in the request header

32 / 35

Theory

33 / 35

Final Review

34 / 35

Final Review

  • What's the difference between authentication and authorization?
34 / 35

Final Review

  • What's the difference between authentication and authorization?

  • What is OAuth?

34 / 35

Final Review

  • What's the difference between authentication and authorization?

  • What is OAuth?

  • Describe the various OAuth 2.0 grant types

34 / 35

Final Review

  • What's the difference between authentication and authorization?

  • What is OAuth?

  • Describe the various OAuth 2.0 grant types

  • How does the grant type affect the OAuth 2.0 authorization flow?

34 / 35

Final Review

  • What's the difference between authentication and authorization?

  • What is OAuth?

  • Describe the various OAuth 2.0 grant types

  • How does the grant type affect the OAuth 2.0 authorization flow?

  • What is OpenID Connect?

34 / 35

Final Review

  • What's the difference between authentication and authorization?

  • What is OAuth?

  • Describe the various OAuth 2.0 grant types

  • How does the grant type affect the OAuth 2.0 authorization flow?

  • What is OpenID Connect?

  • How does OpenID connect work with OAuth 2.0?

34 / 35

Final Review

  • What's the difference between authentication and authorization?

  • What is OAuth?

  • Describe the various OAuth 2.0 grant types

  • How does the grant type affect the OAuth 2.0 authorization flow?

  • What is OpenID Connect?

  • How does OpenID connect work with OAuth 2.0?



🤔

34 / 35

Next Steps

35 / 35

Next Steps

Finish the OpenID Connect + OAuth 2.0 server
  1. Add Refresh Tokens (since Access Tokens are short-lived)
  2. Incorporate Postgres
  3. Address any other TODOs
  4. Review the final code at node-oauth-openid

Anything else?

35 / 35

Next Steps

Finish the OpenID Connect + OAuth 2.0 server
  1. Add Refresh Tokens (since Access Tokens are short-lived)
  2. Incorporate Postgres
  3. Address any other TODOs
  4. Review the final code at node-oauth-openid

Anything else?

Additional Resources
  1. Authentication and Authorization: OpenID vs OAuth2 vs SAML
  2. SAML2 vs JWT: Understanding OpenID Connect Part 1
  3. Libraries: oauth2orize, oauth2-server
35 / 35

Next Steps

Finish the OpenID Connect + OAuth 2.0 server
  1. Add Refresh Tokens (since Access Tokens are short-lived)
  2. Incorporate Postgres
  3. Address any other TODOs
  4. Review the final code at node-oauth-openid

Anything else?

Additional Resources
  1. Authentication and Authorization: OpenID vs OAuth2 vs SAML
  2. SAML2 vs JWT: Understanding OpenID Connect Part 1
  3. Libraries: oauth2orize, oauth2-server
Contact Info
  1. michael@mherman.org
  2. mherman.org
  3. @mikeherman
35 / 35

Next Steps

Finish the OpenID Connect + OAuth 2.0 server
  1. Add Refresh Tokens (since Access Tokens are short-lived)
  2. Incorporate Postgres
  3. Address any other TODOs
  4. Review the final code at node-oauth-openid

Anything else?

Additional Resources
  1. Authentication and Authorization: OpenID vs OAuth2 vs SAML
  2. SAML2 vs JWT: Understanding OpenID Connect Part 1
  3. Libraries: oauth2orize, oauth2-server
Contact Info
  1. michael@mherman.org
  2. mherman.org
  3. @mikeherman
Final Questions? ✌️
35 / 35

Day 1

2 / 35
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow