From 14443cc255735cc25b85f18f83b1fb3b53583de6 Mon Sep 17 00:00:00 2001 From: David Flanagan Date: Tue, 28 Nov 2023 21:27:04 +0000 Subject: [PATCH] fix: redirect url for github apps (#280) --- .changeset/two-crabs-speak.md | 5 +++++ packages/oauth-providers/src/providers/github/githubAuth.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/two-crabs-speak.md diff --git a/.changeset/two-crabs-speak.md b/.changeset/two-crabs-speak.md new file mode 100644 index 00000000..3d345f89 --- /dev/null +++ b/.changeset/two-crabs-speak.md @@ -0,0 +1,5 @@ +--- +'@hono/oauth-providers': patch +--- + +ensure redirect to original URL for GitHub apps diff --git a/packages/oauth-providers/src/providers/github/githubAuth.ts b/packages/oauth-providers/src/providers/github/githubAuth.ts index fbae6ee4..665da022 100644 --- a/packages/oauth-providers/src/providers/github/githubAuth.ts +++ b/packages/oauth-providers/src/providers/github/githubAuth.ts @@ -40,7 +40,11 @@ export function githubAuth(options: { path: '/', // secure: true, }) - return c.redirect(auth.redirect()) + + // OAuth apps can't have multiple callback URLs, but GitHub Apps can. + // As such, we want to make sure we call back to the same location + // for GitHub apps and not the first configured callbackURL in the app config. + return c.redirect(auth.redirect().concat(options.oauthApp ? '' : `&redirect_uri=${c.req.url}`)) } // Retrieve user data from github