Skip to content

Instantly share code, notes, and snippets.

@gr2m
Last active February 24, 2021 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gr2m/fccc47ec74cdf9439b23e14a527f041a to your computer and use it in GitHub Desktop.
Save gr2m/fccc47ec74cdf9439b23e14a527f041a to your computer and use it in GitHub Desktop.
Deno script which uses Octokit with the OAuth Device authentication strategy
/*
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/ask@1.0.6/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