run
npx https://gist.github.com/samrose/eb703dcf5c5eaf2df1575e3b01152cbf| #!/usr/bin/env node | |
| /* eslint-disable no-console, camelcase */ | |
| const { Issuer } = require('openid-client'); | |
| const open = require('open'); | |
| const { ISSUER = 'http://localhost:4000' } = 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; | |
| }); |
| { | |
| "name": "pg", | |
| "version": "1.0.0", | |
| "description": "", | |
| "main": "index.js", | |
| "bin": "./index.js", | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "author": "", | |
| "license": "ISC", | |
| "dependencies": { | |
| "open": "^7.0.0", | |
| "openid-client": "^3.8.3" | |
| } | |
| } |