-
-
Save joelhooks/c585cdab12b986fc7f1a057796e99b76 to your computer and use it in GitHub Desktop.
Simple Device Flow Login CLI implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* eslint-disable no-console, camelcase */ | |
| const { Issuer } = require('openid-client'); | |
| const open = require('open'); | |
| const { ISSUER = 'https://op.panva.cz' } = process.env; | |
| const GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:device_code'; | |
| (async () => { | |
| const issuer = await Issuer.discover(ISSUER); | |
| const client = await issuer.Client.register({ | |
| grant_types: [GRANT_TYPE], | |
| response_types: [], | |
| redirect_uris: [], | |
| token_endpoint_auth_method: 'none', | |
| application_type: 'native', | |
| }); | |
| const handle = await client.deviceAuthorization(); | |
| await open(handle.verification_uri_complete, { wait: false }); | |
| const tokenSet = await handle.poll(); | |
| console.log('got', tokenSet); | |
| console.log('id token claims', tokenSet.claims()); | |
| const userinfo = await client.userinfo(tokenSet); | |
| console.log('userinfo', userinfo); | |
| })().catch((err) => { | |
| console.error(err); | |
| process.exitCode = 1; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "pg", | |
| "version": "1.0.0", | |
| "description": "", | |
| "main": "codeflow.js", | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "author": "", | |
| "license": "ISC", | |
| "dependencies": { | |
| "open": "^7.0.0", | |
| "openid-client": "^3.8.3" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment