MCPcopy Index your code
hub / github.com/gitify-app/gitify / pollGitHubDeviceFlow

Function pollGitHubDeviceFlow

src/renderer/utils/auth/flows.ts:128–160  ·  view source on GitHub ↗
(
  session: DeviceFlowSession,
)

Source from the content-addressed store, hash-verified

126 * @returns The access token when granted, or `null` when still pending.
127 */
128export async function pollGitHubDeviceFlow(
129 session: DeviceFlowSession,
130): Promise<Token | null> {
131 try {
132 const { authentication } = await exchangeDeviceCode({
133 clientType: 'oauth-app' as const,
134 clientId: session.clientId,
135 code: session.deviceCode,
136 request: request.defaults({
137 baseUrl: getGitHubAuthBaseUrl(session.hostname).toString(),
138 }),
139 });
140
141 return authentication.token as Token;
142 } catch (err) {
143 if (err instanceof RequestError) {
144 const response = err.response?.data as DeviceFlowErrorResponse;
145 const errorCode = response.error;
146
147 if (errorCode === 'authorization_pending' || errorCode === 'slow_down') {
148 return null;
149 }
150 }
151
152 rendererLogError(
153 'pollGitHubDeviceFlow',
154 'Error exchanging device code',
155 toError(err),
156 );
157
158 throw err;
159 }
160}
161
162/**
163 * Exchange an OAuth authorization code for an access token.

Callers 1

AppProviderFunction · 0.90

Calls 4

getGitHubAuthBaseUrlFunction · 0.90
rendererLogErrorFunction · 0.90
toErrorFunction · 0.90
toStringMethod · 0.80

Tested by

no test coverage detected