-
-
Save joelhooks/c585cdab12b986fc7f1a057796e99b76 to your computer and use it in GitHub Desktop.
Revisions
-
joelhooks revised this gist
Oct 5, 2023 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ "author": "", "license": "ISC", "dependencies": { "open": "^9.1.0", "openid-client": "^5.6.0" } } -
joelhooks revised this gist
Oct 5, 2023 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,11 +7,10 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "open": "^7.0.0", "openid-client": "^3.8.3" } } -
joelhooks revised this gist
Oct 5, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ { "name": "pg", "version": "1.0.0", "description": "", "main": "index.mjs", -
joelhooks revised this gist
Oct 5, 2023 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ "version": "1.0.0", "description": "", "main": "index.mjs", "bin": "./index.mjs", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, -
joelhooks revised this gist
Oct 5, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,5 +3,5 @@ run ```sh npx https://gist.github.com/joelhooks/c585cdab12b986fc7f1a057796e99b76 ``` -
joelhooks revised this gist
Oct 5, 2023 . 2 changed files with 26 additions and 26 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,35 +2,35 @@ /* 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; }); 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 charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,16 @@ { "name": "test-auth", "version": "1.0.0", "description": "", "main": "index.mjs", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "open": "^9.1.0", "openid-client": "^5.6.0" } } -
panva revised this gist
Apr 29, 2021 . 3 changed files with 11 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ # Simple Device Flow Login CLI implementation run ```sh npx https://gist.github.com/panva/ebaacfe433a8677bdbf458f6e1132045 ``` 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ #!/usr/bin/env node /* eslint-disable no-console, camelcase */ const { Issuer } = require('openid-client'); 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,8 @@ "name": "pg", "version": "1.0.0", "description": "", "main": "index.js", "bin": "./index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, -
panva revised this gist
Nov 22, 2019 . 2 changed files with 6 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ /* 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'; @@ -19,7 +19,7 @@ const GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:device_code'; const handle = await client.deviceAuthorization(); await open(handle.verification_uri_complete, { wait: false }); const tokenSet = await handle.poll(); 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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,15 @@ { "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" } } -
panva revised this gist
Nov 22, 2019 . 2 changed files with 6 additions and 44 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,13 @@ /* eslint-disable no-console, camelcase */ const { Issuer } = require('openid-client'); const opn = require('opn'); 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], @@ -23,44 +17,14 @@ const SOFT_ERRORS = new Set(['authorization_pending', 'slow_down']); application_type: 'native', }); const handle = await client.deviceAuthorization(); await opn(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); 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 charactersOriginal file line number Diff line number Diff line change @@ -9,9 +9,7 @@ "author": "", "license": "ISC", "dependencies": { "openid-client": "^3.8.3", "opn": "^5.3.0" } } -
panva revised this gist
Jul 23, 2018 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ { "name": "example", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "base64url": "^3.0.0", "got": "^8.3.2", "openid-client": "^2.2.1", "opn": "^5.3.0" } } -
panva renamed this gist
Jul 23, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
panva created this gist
Jul 23, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ /* eslint-disable no-console, camelcase */ const { randomBytes, createHash } = require('crypto'); const { encode } = require('base64url'); const { post } = require('got'); const { Issuer } = require('openid-client'); const opn = require('opn'); const { ISSUER = 'https://guarded-cliffs-8635.herokuapp.com' } = process.env; const GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:device_code'; const SOFT_ERRORS = new Set(['authorization_pending', 'slow_down']); (async () => { const issuer = await Issuer.discover(ISSUER); const { device_authorization_endpoint } = issuer; const client = await issuer.Client.register({ grant_types: [GRANT_TYPE], response_types: [], redirect_uris: [], token_endpoint_auth_method: 'none', application_type: 'native', }); const code_verifier = randomBytes(8).toString('hex'); const code_challenge = encode(createHash('sha256').update(code_verifier).digest()); const { body: { device_code, verification_uri_complete }, } = await post(device_authorization_endpoint, { json: true, form: true, body: { client_id: client.client_id, scope: 'openid email', code_challenge, code_challenge_method: 'S256', claims: JSON.stringify({ id_token: { email: null } }), }, }); await opn(verification_uri_complete, { wait: false }); const tokenSet = await new Promise((resolve, reject) => { function poll() { client.grant({ grant_type: GRANT_TYPE, device_code, code_verifier, }).then(resolve, (err) => { if (err.name === 'OpenIdConnectError' && SOFT_ERRORS.has(err.error)) { setTimeout(poll, 3000); } else { reject(err); } }); } setTimeout(poll, 3000); }); 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; });