Simple demo for OAuth 2.0 Device Code Grant
for a CLI
app in action, using Auth0
and NodeJS
.
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.
- Docker
- Docker Compose (optional)
A step by step series of examples that tell you how to get a development env running.
- Clone this repository.
git clone repo
- Change to repo folder
cd repo
-
Edit
.env
files with your values (optional) -
Run Docker Compose
docker-compose up
Docker Compose
will start the two containers vizAPI
container andDevice
container.- The
API
service will start listening for new requests. - The
Device
script will call out toAuth0
for aDevice Code
&User Code
for making secure request to theAPI
. - The
Device
then renders theQRCode
for theVerification URI
generated byAuth0
. - 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). - During the time that the user is doing all of the above, the
Device
script will keep polling againstAuth0
for anAccess Token
. - Once the user is done with the steps mentioned above,
Auth0
issues anAccess Token
with appropriatescopes
. - The
Device
can now make a secureAPI
call.
$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