dgrubelic / vue-authenticate

Simple Vue.js authentication library
1.43k stars 251 forks source link

request token with optional params #194

Open clearcodecn opened 4 years ago

clearcodecn commented 4 years ago

this is the code in src/oauth/oauth2.js

  exchangeForToken(oauth, userData) {
  ...
      // we don't use the value we configed, and is this a bug?
      // I am using comtom oauth2 server and I thinks we should use this.
      let value = this.providerConfig.responseParams[key]
 ... 
      switch(key) {
        case 'code':
          payload[key] = oauth.code
          break
        case 'clientId':
          payload[key] = this.providerConfig.clientId
          break
        case 'redirectUri':
          payload[key] = this.providerConfig.redirectUri
          break
        default:
          payload[key] = oauth[key]  || value // we can use there.
      }
    }

  }
clearcodecn commented 4 years ago

demo of my config:

Vue.use(VueAuthenticate, {
  baseUrl: process.env.BASE_URL || 'http://localhost:8082', // Your API domain
  providers: {
    gopher1024: {
      clientId: 'spa',
      name: 'myapp',
      url: '/sso/token',
      authorizationEndpoint: 'http://localhost:8082/sso/authorize',
      redirectUri: 'http://localhost:7001/oauth2',
      requiredUrlParams: ['scope'],
      defaultUrlParams: ['response_type', 'client_id', 'redirect_uri'],
      responseParams: {
        grant_type: 'authorization_code',
      },
      scope: ['all'],
      scopeDelimiter: ',',
      oauthType: '2.0',
    },
  }
})

oauth succeed but request token failed with request and response below:

GET http://localhost:8082/sso/token
{"code":"9Z3LNUN4MHOURR_NIRSEWQ","clientId":"spa","redirectUri":"http://localhost:7001/oauth2"}

{"error":"unsupported_grant_type","error_description":"The authorization grant type is not supported by the authorization server"}

I was configed grant_type:authorization_code in my config but it's no used.

rslifka commented 4 years ago

Hah, I just requested this too. Are you trying to authenticate with Bungie? Did you ever figure it out? :)

rslifka commented 4 years ago

If you want to use parameters that aren't currently in vue-authentication, use the axios request interceptor as documented in the README.md. It's a big hammer to hit the problem with, but it works :) Good luck!