-
-
Notifications
You must be signed in to change notification settings - Fork 151
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
How to use and decode state parameter #80
Comments
hey @eric72 how did you make it work? |
I didn't used it at the end for the moment, did you resolved the same issue ? |
hm it worked for me: const authUser = async (
req: Request,
_accessToken: unknown,
_refreshToken: unknown,
authProfile: unknown,
): Promise<void> => {
JSON.parse(req.query.state)
};
passport.use(new PassportGoogle.Strategy(
{
clientID: params.clientId,
clientSecret: params.clientSecret,
callbackURL: '/users/auth/google/callback',
scope: ['profile', 'email'],
passReqToCallback: true,
}, authUser),
);
router.get('/auth/google', (req, res, next) => {
const state = JSON.stringify(parsedSchema.data);
passport.authenticate('google', { state })(req, res, next);
});
router.get('/auth/google/callback', (req, res, next) => {
passport.authenticate('google', { authInfo: true }, async (err, args: OauthPayload) => {
console.log(args.state.origin);
})(req, res, next);
}); |
This fails in Typescript as |
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I added in my app the state parameter like that:
constructor() {
super({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_SECRET,
callbackURL: 'my callback url',
state: JSON.stringify({ "redirectUrl" : "test" }),
scope: ['email', 'profile'],
});
}
now when i get it from my request i get my state encoded.
I try to decode it and get my : { "redirectUrl" : "test" } .
But it's not working.
How can i get it ?
I already tried this :
Buffer.from(req.query.state, 'base64').toString('ascii');
Buffer.from(req.query.state).toString('utf-8'));
Buffer.from(req.query.state).toString('ascii'));
But i can't decode it and get my : { "redirectUrl" : "test" } .
Is it possible to get it ?
Thanks,
The text was updated successfully, but these errors were encountered: