Last active
February 24, 2021 23:55
-
-
Save gr2m/fccc47ec74cdf9439b23e14a527f041a to your computer and use it in GitHub Desktop.
Deno script which uses Octokit with the OAuth Device authentication strategy
This file contains 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
/* | |
Install Deno at https://deno.land/. Then run: | |
deno run --allow-net https://gist.githubusercontent.com/gr2m/fccc47ec74cdf9439b23e14a527f041a/raw/db2f15d118d201cb3d2cb55cb329a856977205b9/index.ts | |
Learn more: | |
- https://docs.github.com/en/developers/apps/authorizing-oauth-apps#device-flow | |
- https://github.com/octokit/auth-oauth-device.js#readme | |
*/ | |
import Ask from "https://deno.land/x/[email protected]/mod.ts"; | |
import { createOAuthDeviceAuth } from "https://cdn.pika.dev/@octokit/auth-oauth-device?dts"; | |
import { Octokit } from "https://cdn.pika.dev/@octokit/core?dts"; | |
const ask = new Ask(); | |
const octokit = new Octokit({ | |
authStrategy: createOAuthDeviceAuth, | |
auth: { | |
clientId: "af3540296c43be2ada1c", // test OAuth app by @gr2m | |
async onVerification(verification: any) { | |
console.log("Open %s", verification.verification_uri); | |
console.log("Enter code: %s", verification.user_code); | |
const { name } = await ask.input({ | |
type: "confirm", | |
name: "continue", | |
message: "Press <enter> once access was granted", | |
}); | |
}, | |
}, | |
}); | |
const { data: me } = await octokit.request("GET /user"); | |
console.log(me); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment