run
npx https://gist.github.com/joelhooks/c585cdab12b986fc7f1a057796e99b76| #!/usr/bin/env node | |
| /* eslint-disable no-console, camelcase */ | |
| import { Issuer } from 'openid-client'; | |
| import open from 'open'; | |
| const { ISSUER = 'https://www.epicweb.dev/oauth' } = 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.mjs", | |
| "bin": "./index.mjs", | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "author": "", | |
| "license": "ISC", | |
| "dependencies": { | |
| "open": "^7.0.0", | |
| "openid-client": "^3.8.3" | |
| } | |
| } |