Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specific information through the login process #66

Closed
ramiel opened this issue Sep 13, 2016 · 5 comments
Closed

Specific information through the login process #66

ramiel opened this issue Sep 13, 2016 · 5 comments

Comments

@ramiel
Copy link

ramiel commented Sep 13, 2016

Hi, thank you for this amazing project!
I have this requirement and I'm wondering if I can accomplish it with your library. Depending on some parameters, just after the login I have to assign a different role to the logged user.
This means that I'd want to specify "log the user with the provider and after assign him the role X".
I cannot instantiate two provider for the same type (and I don't need to), but how can I "inform" the callback that the login process has started in one way or another, that the role X has been requested?

@simov
Copy link
Owner

simov commented Sep 13, 2016

You can write your own connect route, add some state in the user's session, and then redirect to the actual connect route that Grant uses. Then inside the final callback you will have access to both the response data from the OAuth flow, and the user's state stored earlier in the session.

@ramiel
Copy link
Author

ramiel commented Sep 13, 2016

Is what you call dynamic override in the documentation?

@simov
Copy link
Owner

simov commented Sep 13, 2016

No, it's something like this:

app.get('/connect_facebook', function (req, res) {
  req.session.mydata = 'hey'
  res.redirect('/connect/facebook')
})

app.get('/handle_facebook_callback', function (req, res) {
  console.log(req.session.mydata) // hey
  // the oauth response is either in req.query or req.session.grant as usual
})

@ramiel
Copy link
Author

ramiel commented Sep 13, 2016

Well, thank you, I'll try

@ramiel
Copy link
Author

ramiel commented Sep 13, 2016

Ok, it's works, great solution!

@ramiel ramiel closed this as completed Sep 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants