Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add authorizationParams in oauth config #56

Merged
merged 2 commits into from
Feb 17, 2024
Merged

Conversation

atinux
Copy link
Owner

@atinux atinux commented Feb 17, 2024

Resolves #22
Resolves #43 by overwriting redirect_uri in authorizationParams

This pull request introduce authorizationParams option in each OAuth provider, example:

export default oauth.googleEventHandler({
  config: {
    authorizationParams: {
      access_type: 'offline'
    }
  },
  async onSuccess(event, { user }) {
    // ...
  }
})

The authorizationParams can overwrite the generated params we provide and this can be useful in case such as #43

export default oauth.microsoftEventHandler({
  config: {
    authorizationParams: {
      redirect_uri: 'https://my-custom-redirect-uri'
    }
  },
    async onSuccess(event, { user }) {
      // ...
    }
})

@atinux atinux merged commit 5c79590 into main Feb 17, 2024
3 checks passed
@atinux atinux deleted the feat/auth-params branch February 17, 2024 16:20
@PGLongo
Copy link

PGLongo commented Mar 27, 2024

@atinux I think that #56 doest not fix this.

    if (!code) {
      const scope = config.scope && config.scope.length > 0 ? config.scope : ['User.Read']
      // Redirect to Microsoft Oauth page
      return sendRedirect(
        event,
        withQuery(authorizationURL as string, {
          client_id: config.clientId,
          response_type: 'code',
          redirect_uri: redirectUrl,
          scope: scope.join(' '),
          ...config.authorizationParams
        })
      )
    }

The problem was the line

const redirectUrl = getRequestURL(event).href'

but this line is not affected by #56.

I think that it should be something like:

const redirectUrl = config.authorizationParams?.redirect_uri || getRequestURL(event).href

Do you agree with me?

@atinux
Copy link
Owner Author

atinux commented Mar 28, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Utils does not work with Azure SWA Add option for additional query parameters
2 participants