Skip to content

Simple demo for `OAuth 2.0 Device Code Grant` for a `CLI` app in action, using `Auth0` and `NodeJS`.

Notifications You must be signed in to change notification settings

jatinvaidya/cli-authz-device-flow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OAuth2.0 Device Code Grant Demo for CLI app using Auth0

Table of Contents

About

Simple demo for OAuth 2.0 Device Code Grant for a CLI app in action, using Auth0 and NodeJS.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

  • Docker
  • Docker Compose (optional)

Install & Run

A step by step series of examples that tell you how to get a development env running.

  1. Clone this repository.
git clone repo
  1. Change to repo folder
cd repo
  1. Edit .env files with your values (optional)

  2. Run Docker Compose

docker-compose up

Solution Flow

  1. Docker Compose will start the two containers viz API container and Device container.
  2. The API service will start listening for new requests.
  3. The Device script will call out to Auth0 for a Device Code & User Code for making secure request to the API.
  4. The Device then renders the QRCode for the Verification URI generated by Auth0.
  5. The User must scan this QRCode using their mobile device and follow the instructions (viz. confirm the user_code, authenticate and grant consent to the device to call the API on the users behalf).
  6. During the time that the user is doing all of the above, the Device script will keep polling against Auth0 for an Access Token.
  7. Once the user is done with the steps mentioned above, Auth0 issues an Access Token with appropriate scopes.
  8. The Device can now make a secure API call.

Sample Run

$docker-compose up                  
Creating network "device-flow-demo-network" with the default driver
Creating device-flow-demo-device ... done
Creating device-flow-demo-api    ... done
Attaching to device-flow-demo-api, device-flow-demo-device
device-flow-demo-api | 
device-flow-demo-api | > api@1.0.0 start /opt/api
device-flow-demo-api | > node api.js
device-flow-demo-api | 
device-flow-demo-device | 
device-flow-demo-device | > device@1.0.0 start /opt/device
device-flow-demo-device | > node device.js
device-flow-demo-device | 
device-flow-demo-api | Now listening on http://localhost:9090
device-flow-demo-device | {
device-flow-demo-device |   device_code: 'MP1tg1h_9ArOZjWPUJBgmu0v',
device-flow-demo-device |   user_code: 'JRFG-ZXBS',
device-flow-demo-device |   verification_uri: 'https://jv-device.au.auth0.com/activate',
device-flow-demo-device |   expires_in: 900,
device-flow-demo-device |   interval: 5,
device-flow-demo-device |   verification_uri_complete: 'https://jv-device.au.auth0.com/activate?user_code=JRFG-ZXBS'
device-flow-demo-device | }

 █ ▄▄▄ █ █▄▄███▀█▄▄▄ █ ▀▀  █ ▄▄▄ █
 █ ███ █ ▄▀▀▀ ██▀██▀▀ ▄▀▄▄ █ ███ █
 █▄▄▄▄▄█ █▀▄▀▄▀█▀▄▀█▀▄ █ ▄ █▄▄▄▄▄█
 ▄▄ ▄  ▄▄▀▀▄ ▀ ▀ █▀▀▀▄█ █  ▄▄▄ ▄▄ 
 ▄▀▄▄▀▄▄▀█▄█▀  ▀▀▀█▄▄▀ ▄ ▄██▄ █  █
 █ █▄▀▄▄█▀   ▄ ▀█ ▄▀▀ ██▄▄▄▄▀▀▄ ▀█
 ▀▄▄▀ ▄▄█▄▄▀▀█  ▀▄  ▀█▄▀▄█▄▀ ▀█▀█▀
  ▄▄█ ▄▄▄▀▄ ▄▀██▄▄█▀ ▀██▀▀▄▄▄▄▀ ▀▄
 ▀ ▀██ ▄ █▄█  ▄ ▀▀   ▀▀▄▀▀█ ▄▄█▀▄▄
  ▄ █▀▀▄█████▄▀▄█▄▀  ▀█ █▀▄▀ ▀█ ▄ 
 ▄█ █ ▀▄█ ▀ ███▄ ▄▀ ▄██  ▀██  ▄▀ █
 ▄▀▀▄▄ ▄ ██▀█▀▀▄ █▄█▀ █▀ ▄▄█▄▄▀ ▀▀
 ▄▄▄▄▄▄▄ ████ ██▀▄▄▀▀█▀ ▀█ ▄ ██▀▄▀
 █ ▄▄▄ █  ▄█▀▄▄  ▀▀▀█▄█▄ █▄▄▄█▄ ▄▀
 █ ███ █ ▀█▀▄█▀█▀██▄ ▄ ▄▄▀▄▀██▀  ▄
 █▄▄▄▄▄█ █▄  ▀ ▀ ▀█ ▀██ ███ ▄▀█ ▄ 

device-flow-demo-device |                                                                       
device-flow-demo-device | polling ...
device-flow-demo-device | {
device-flow-demo-device |   error: 'authorization_pending',
device-flow-demo-device |   error_description: 'User has yet to authorize device code.'
device-flow-demo-device | }
device-flow-demo-device | polling ...
device-flow-demo-device | {
device-flow-demo-device |   error: 'authorization_pending',
device-flow-demo-device |   error_description: 'User has yet to authorize device code.'
device-flow-demo-device | }
device-flow-demo-device | polling ...
device-flow-demo-device | {
device-flow-demo-device |   error: 'authorization_pending',
device-flow-demo-device |   error_description: 'User has yet to authorize device code.'
device-flow-demo-device | }
device-flow-demo-device | polling ...
device-flow-demo-device | {
device-flow-demo-device |   error: 'authorization_pending',
device-flow-demo-device |   error_description: 'User has yet to authorize device code.'
device-flow-demo-device | }
device-flow-demo-device | polling ...
device-flow-demo-device | {
device-flow-demo-device |   error: 'authorization_pending',
device-flow-demo-device |   error_description: 'User has yet to authorize device code.'
device-flow-demo-device | }
device-flow-demo-device | polling ...
device-flow-demo-device | received access token, stop polling ...
device-flow-demo-device | calling api with access token ...
device-flow-demo-device | api response: "Hello, Device!"
device-flow-demo-device exited with code 0

About

Simple demo for `OAuth 2.0 Device Code Grant` for a `CLI` app in action, using `Auth0` and `NodeJS`.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published