( hostname: Hostname = Constants.GITHUB_HOSTNAME, scopes: string[] = getRecommendedScopeNames(), )
| 92 | * @returns The device flow session data. |
| 93 | */ |
| 94 | export async function startGitHubDeviceFlow( |
| 95 | hostname: Hostname = Constants.GITHUB_HOSTNAME, |
| 96 | scopes: string[] = getRecommendedScopeNames(), |
| 97 | ): Promise<DeviceFlowSession> { |
| 98 | const deviceCode = await createDeviceCode({ |
| 99 | clientType: 'oauth-app' as const, |
| 100 | clientId: Constants.OAUTH_DEVICE_FLOW_CLIENT_ID, |
| 101 | scopes: scopes, |
| 102 | request: request.defaults({ |
| 103 | baseUrl: getGitHubAuthBaseUrl(hostname).toString(), |
| 104 | }), |
| 105 | }); |
| 106 | |
| 107 | return { |
| 108 | hostname: hostname, |
| 109 | clientId: Constants.OAUTH_DEVICE_FLOW_CLIENT_ID, |
| 110 | deviceCode: deviceCode.data.device_code, |
| 111 | userCode: deviceCode.data.user_code, |
| 112 | verificationUri: deviceCode.data.verification_uri, |
| 113 | intervalSeconds: deviceCode.data.interval, |
| 114 | expiresAt: Date.now() + deviceCode.data.expires_in * 1000, |
| 115 | } as DeviceFlowSession; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Poll GitHub to exchange a device code for an access token. |
no test coverage detected