diadal / universal-social-auth

SPA universal social auth
MIT License
40 stars 11 forks source link

Last two digits of clientId are being replaced with 00 #20

Closed whoacowboy closed 1 year ago

whoacowboy commented 1 year ago

Describe the bug When creating a Discord social login, universal-social-auth will cut off the last two digital of my Discord clientId which ends with 77 but it replaces them with zeros. If I replace the last two zeros in the URI with 77, everything works. Is there a setting for clientId length that I am missing?

const Discord = {
  name: 'discord',
  url: '/auth/discord',
  authorizationEndpoint: 'https://discord.com/api/oauth2/authorize',
  tokenURL: 'https://discord.com/api/oauth2/token',
  redirectUri: window.location.origin,
  scopeDelimiter: '%20',
  sessionKey: 'oauth:discord',
  oauthType: '2.0',
  requiredUrlParams: ['scope'],
  scope: ['identify', 'email'],
  popupOptions: { width: 495, height: 645 },
}

export { Discord }

https://discord.com/oauth2/authorize?response_type=code&client_id=*****************00&redirect_uri=https://my.site:8080/auth/discord/callback&scope=identify%20email

I did a little bit of investigation and it looks like this issue has to do with Discord using a completely numeric clientId.

This piece of code seems to be the issue.

https://github.com/diadal/universal-social-auth/blob/e637bc63577c93307907ca5d904d08b451311ec3/src/utils.ts#L67-L80

I made this codepen that demonstrates the issue.

https://codepen.io/whoacowboy/pen/VwVrBpr

I think it has to do with the the number being larger than JavaScipt can handle as an integer.

https://stackoverflow.com/questions/4557509/javascript-summing-large-integers

I tried wrapping the clientId in quotes and that did not fix the issue.

whoacowboy commented 1 year ago

If I write it as a string in my options object, it works as expected.

export default async ({ app }) => {
  const options = {
    providers: {
      discord: {
        clientId: '*****************77',
        redirectUri: process.env.DISCORD_REDIRECT_URL,
      }
  }
  const Oauth = new UniversalSocialauth(axios, options)
  app.config.globalProperties.$Oauth = Oauth
  app.provide('$Oauth', Oauth)
}
diadal commented 1 year ago

can you submit the PR for the codepen patch

whoacowboy commented 1 year ago

Once I get it working I will.

It looks like it might be an issue with dotenv converting the string to a number.

The number is too large for JS so it rounds it up or down.

Once I figure it out I'll let you know.

whoacowboy commented 1 year ago

It was my dotenv configuration.