tpcofficial / big-oauth2

A OAuth2 module to easily allow you to integrate your applications authentication with 3rd party IdPs. Returns user data with minimal code to help you create and manage users in your databases!
GNU General Public License v3.0
3 stars 1 forks source link

[Bug] fetch not a function in Discord/Google.stopFlow #18

Closed dudeisbrendan03 closed 3 years ago

dudeisbrendan03 commented 3 years ago

Describe the bug 0.1.43 - this.libs.fetch is not a function

Stack:

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
TypeError: this.libs.fetch(...).this is not a function
    at DiscordHandler.stopFlow (C:\Users\Brendan\source\repos\big-oauth2-testing\node_modules\@tpcofficial\big-oauth2\providers\discord.js:45:18)
    at C:\Users\Brendan\source\repos\big-oauth2-testing\express.js:74:41
    at Layer.handle [as handle_request] (C:\Users\Brendan\source\repos\big-oauth2-testing\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\Brendan\source\repos\big-oauth2-testing\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\Users\Brendan\source\repos\big-oauth2-testing\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\Users\Brendan\source\repos\big-oauth2-testing\node_modules\express\lib\router\layer.js:95:5)
    at C:\Users\Brendan\source\repos\big-oauth2-testing\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (C:\Users\Brendan\source\repos\big-oauth2-testing\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\Brendan\source\repos\big-oauth2-testing\node_modules\express\lib\router\index.js:275:10)
    at Function.handle (C:\Users\Brendan\source\repos\big-oauth2-testing\node_modules\express\lib\router\index.js:174:3)

discord.js:41-48

    async stopFlow(flowResponse) {//Should receive the token, automatically and prepare it for the user - the token is not stored and this should return USER DATA only
        if (!flowResponse || (!flowResponse.code || !flowResponse.access_token))
            return false

        if (flowResponse.accces_token && flowResponse.token_type == 'Bearer') {
            await this.libs.fetch(`https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=${json.accces_token}`)
                .this(json => {return json})
        } else {

express.js:72-75

router.get('/discord/callback', async (res, req, next) => {
    console.info('\n'+JSON.stringify(res.query)+'\n')
    const userdata = await DiscordOAuth.stopFlow({code:res.query.code})
})

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

sentry-io[bot] commented 3 years ago

Sentry issue: BIG-OAUTH2-E

sentry-io[bot] commented 3 years ago

Sentry issue: BIG-OAUTH2-C

dudeisbrendan03 commented 3 years ago

Rewrote how the exchange is handled with @0xh4sh

Commit

Needs implementing into the Discord provider