set state value when redirect
sangemi opened this issue · 0 comments
Why this feature is required (specific use-cases will be appreciated)?
Frontend is nuxt, and backend is adonisjs.
What I want to do is, when user click the login button once, frontend nuxt and backend adonisjs is logged in at the same time.
When users click the login button,
In the backend Ally run oauth process and backend will be logged in.
But my frontend nuxt is not logged in not yet.
Ally have to send a token which is delivered from google etc.
In the frontend, to make nuxt auth logged in, I wish that nuxt will receive the token from adonis ally which is same with google's token.
At this step, nuxt-auth checks the state value is same.
At the first time, nuxt-auth's oauth make a state value using nanoid(), or we can set custom state value.
So we have to send a token which is generated by nuxt-auth.
So we need to set the state value when ally's redirect.
Are you willing to work on it with little guidance?
Below is simple code to suggest
SomeController.js
async redirect({ally, params, request}) {
const req = request.all()
await ally.driver('google').redirect(req.state)
}
ally/src/Authenticator.js
async redirect (custom_state = null) {
let state = null
if (!this._isStateless && this._driverInstance.supportStates) {
state = (custom_state)?custom_state:uuid()
this._response.cookie('oauth_state', state, this._cookieOptions)
}
const url = await this.getRedirectUrl(state)
this._response.status(302).redirect(url)
}
or state method
await ally.driver('google').state(req.state).redirect()