Created
February 21, 2018 20:49
-
-
Save colinrymer/ef13b71bb7ef9022b5807baac08bbc37 to your computer and use it in GitHub Desktop.
Example api client code
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 characters
| import * as Octokit from '@octokit/rest' | |
| const client = new Octokit() | |
| export default class GithubClient { | |
| public static async authenticate({username, password, twoFactorCode}: any) { | |
| client.authenticate({ | |
| type: 'basic', | |
| username: username, | |
| password: password | |
| }) | |
| const {data: {token}} = await client.authorization.create({ | |
| scopes: ['repo'], | |
| headers: { | |
| 'x-github-otp': twoFactorCode | |
| } | |
| } as Octokit.AuthorizationCreateParams) | |
| return token | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently, calling
GithubClient.authenticatewith a bogus twoFactorCode, e.g.'000000'for users that do not have 2FA enabled successfully returns a personal access token. Is this undocumented but expected behavior?