Skip to content

Commit

Permalink
Merge pull request #1496 from argos-ci/github-oauth-response-log
Browse files Browse the repository at this point in the history
chore: add logs to understand GitHub OAuth failure
  • Loading branch information
gregberge authored Jan 2, 2025
2 parents 115ad9f + 8b1bb9b commit 217da9d
Showing 1 changed file with 27 additions and 30 deletions.
57 changes: 27 additions & 30 deletions apps/backend/src/github/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as Sentry from "@sentry/node";
import axios from "axios";
import { z } from "zod";

import logger from "@/logger";

const RetrieveTokenResponseSchema = z.object({
access_token: z.string(),
token_type: z.literal("bearer"),
Expand All @@ -14,36 +15,32 @@ export async function retrieveOAuthToken(args: {
code: string;
redirectUri: string;
}) {
return Sentry.withScope(async (scope) => {
const body = {
client_id: args.clientId,
client_secret: args.clientSecret,
code: args.code,
redirect_uri: args.redirectUri,
};

scope.setExtra("body", body);
const body = {
client_id: args.clientId,
client_secret: args.clientSecret,
code: args.code,
redirect_uri: args.redirectUri,
};

const result = await axios.post(
"https://github.com/login/oauth/access_token",
body,
{
headers: {
accept: "application/json",
},
const result = await axios.post(
"https://github.com/login/oauth/access_token",
body,
{
headers: {
accept: "application/json",
},
);
},
);

try {
return RetrieveTokenResponseSchema.parse(result.data);
} catch (error) {
scope.setExtra("errorResponse", {
status: result.status,
data: result.data,
});
throw new Error("Failed to parse GitHub OAuth response", {
cause: error,
});
}
});
try {
return RetrieveTokenResponseSchema.parse(result.data);
} catch (error) {
logger.info("GitHub OAuth response errored", {
status: result.status,
data: result.data,
});
throw new Error("Failed to parse GitHub OAuth response", {
cause: error,
});
}
}

0 comments on commit 217da9d

Please sign in to comment.