ally icon indicating copy to clipboard operation
ally copied to clipboard

Exception: E_OAUTH_STATE_MISMATCH (Ally 2.1.3)

Open muhx opened this issue 6 years ago • 3 comments

Package version

"@adonisjs/ace": "^5.0.8", "@adonisjs/ally": "^2.1.3", "@adonisjs/auth": "^3.0.7", "@adonisjs/bodyparser": "^2.0.5", "@adonisjs/cors": "^1.0.7", "@adonisjs/fold": "^4.0.9", "@adonisjs/framework": "^5.0.9", "@adonisjs/ignitor": "^2.0.8", "@adonisjs/lucid": "^6.1.3", "@adonisjs/session": "^1.0.27", "@adonisjs/shield": "^1.0.8", "pg": "^7.17.1"

Node.js and npm version

node -v = v12.13.1 npm -v = 6.12.1

Sample Code (to reproduce the issue)

I have this exception when I try to access to Google API since I upgraded Ally to version 2.1.3. This code works on the previous version (2.1.1)

  • start/routes.js
Route.get('login/google', 'LoginController.redirect')
Route.get('google/callback', 'LoginController.callback')
  • app/Controllers/Http/LoginController
'use strict'
const User = use('App/Models/User.js')

class LoginController {
  async redirect ({ ally }){
    await ally.driver('google').redirect()
  }

  async callback ({ ally, auth }) {
    try {
      const gUser = await ally.driver('google').getUser();

      const userDetails = {
        email: gUser.getEmail(),
        token: gUser.getAccessToken(),
        login_source: 'google'

      };

      const whereClause = {
        email: gUser.getEmail()
      };

      const user = await User.findOrCreate(whereClause, userDetails)
      await auth.login(user)
    } catch (e) {
      console.log(e);
      return 'Unable to authenticate. Please contact support'
    }
  }
}

module.exports = LoginController

muhx avatar Jan 27 '20 10:01 muhx

I'm also getting E_OAUTH_STATE_MISMATCH when using stateless method and custom state parameters.

The code section that is wrong:

MyController.js
await ally.driver(provider).stateless().getUser()

src/Drivers/Google.js
if (state && originalState !== state) {
      throw CE.OAuthException.invalidState()
}

State variable is my custom string and originalState is null.

goraSi avatar May 01 '20 14:05 goraSi

Hi @thetutlage , I'm also getting this error even after downgrading to v2.1.1 can you advice on what to do here?

vic3king avatar May 11 '20 01:05 vic3king

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 26 '20 17:12 stale[bot]