Reputation: 3902
A user logs into my site through oauth via the url
http://provemath.org/index?method=google&state=KasQzeMyWQj3YTvF4aZGi9smLUMwXa&code=4/OAeBwzZLSqoHtwBgEHojEQ1_FFO7TK03j5UUyF2Bdng#
I don't really like the messiness of the parameters in the URL, and currently it causes an issue when they reload. So what I'd like to do is redirect them to provemath.org in order to get those parameters out of the URL, but pass those same variables along some other way.
Is it possible to do a redirect (something like self.redirect('http://provemath.org', self.request.uri)
) and pass in some variables not through the URL?
It doesn't look like the possibility is built-in:
http://www.tornadoweb.org/en/stable/_modules/tornado/web.html#RequestHandler.redirect
Upvotes: 1
Views: 1775
Reputation: 22134
It's not a part of the redirect itself, but you can pass this kind of information around with cookies (and this is the usual way of handling an oauth redirect). Typically with oauth you would configure your oauth callback URL to be something like provemath.org/oauth
(not provemath.org/index
), and then in your /oauth
handler you'd process the parameters and set a cookie. If you're using tornado.auth.GoogleOAuth2Mixin
this would look like
user = yield self.get_authenticated_user(
redirect_uri='http://provemath.org/oauth',
code=self.get_argument('code'))
self.set_secure_cookie("user", json.dumps(user))
self.redirect("/")
(or save user
to a database and just put a user id in the cookie)
Upvotes: 2