W
Wasp-langβ€’3mo ago
otrojka

Github Oauth additional query parameters

Hello πŸ‘‹ , I am having trouble to include additional query parameter inside Oauth flow using wasp. The default authorize call made by wasp generated src looks like https://github.com/login/oauth/authorize?response_type=code&client_id=xxx&state=xxx&scope=user%3Aemail and I need to specify additional parameter:redirect_uri (details https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#1-request-a-users-github-identity) However, the docs mentions only support for scopes using configFn -> https://wasp-lang.dev/docs/auth/social-auth/github#configfn-extimport Any ideas how to do that?
5 Replies
kapa.ai
kapa.aiβ€’3mo ago
Hi @otrojka. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hello! Currently, the Wasp framework's GitHub OAuth implementation allows you to specify the scopes via the configFn function as you've mentioned. However, the redirect_uri parameter is not directly configurable through the configFn function according to the provided documentation (https://wasp-lang.dev/docs/auth/social-auth/github#configfn-extimport). The redirect_uri is typically handled by the OAuth library and is set to the callback URL of your application. In the case of Wasp, this would be <http://localhost:3001/auth/github/callback> for development or <https://your-server-url.com/auth/github/callback> for production as mentioned in the documentation (https://wasp-lang.dev/docs/auth/social-auth/github#3-creating-a-github-oauth-app). If you need to customize the redirect_uri beyond this, it might require changes to the Wasp source code or the underlying OAuth library it uses. I would recommend raising this as a feature request on the Wasp GitHub issues page (https://github.com/wasp-lang/wasp/issues) for further assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @otrojka, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Vinny (@Wasp)
Vinny (@Wasp)β€’3mo ago
would the Auth Hooks come in handy here https://wasp-lang.dev/docs/auth/auth-hooks
Auth Hooks | Wasp
Auth hooks allow you to "hook into" the auth process at various stages and run your custom code. For example, if you want to forbid certain emails from signing up, or if you wish to send a welcome email to the user after they sign up, auth hooks are the way to go.
Vinny (@Wasp)
Vinny (@Wasp)β€’3mo ago
Why do you need to change your redirectUri?
otrojka
otrojkaβ€’3mo ago
Thanks Vinny πŸ™ Finally I made it work using the OnBeforeOAuthRedirectHook from newly introduced AuthHooks
import type { OnBeforeOAuthRedirectHook } from 'wasp/server/auth'

export const onBeforeOAuthRedirect: OnBeforeOAuthRedirectHook = async ({
url,
uniqueRequestId,
prisma,
req,
}) => {
const redirectUri = "http://localhost:3001/auth/github/callback"
url.searchParams.append('redirect_uri', redirectUri);
return { url }
}
import type { OnBeforeOAuthRedirectHook } from 'wasp/server/auth'

export const onBeforeOAuthRedirect: OnBeforeOAuthRedirectHook = async ({
url,
uniqueRequestId,
prisma,
req,
}) => {
const redirectUri = "http://localhost:3001/auth/github/callback"
url.searchParams.append('redirect_uri', redirectUri);
return { url }
}
I want to use single Github Oauth App for multiple sites. Because I am using authorization on documentation site as well (on different domain). Moreover Github only support single callback domain which can be only slightly modified using redirect_uri.
Vinny (@Wasp)
Vinny (@Wasp)β€’3mo ago
ok cool! glad you got it working
Want results from more Discord servers?
Add your server