Get the uri of the page from which the sign in was requested

106 views
Skip to first unread message

Jason Baik

unread,
May 31, 2015, 2:46:46 PM5/31/15
to google-iden...@googlegroups.com
Hi All, 

I'm using gitkit v3 for web.
Does anybody know a clever way to make the browser navigate back to the page from which the sign-in was requested?

In other words, when the sign-in button is pressed, the user's taken to the widget url. When his sign-in is successful, the widget would redirect the user to the "signInSuccessUrl", which is passed as one of the config params at widget initialization. My question is, how can I make this "signInSuccessUrl" dynamic, and make it the page from which the sign-in button was pressed?

** I don't want to use any cookies.

Derek Salama

unread,
May 31, 2015, 4:15:26 PM5/31/15
to google-iden...@googlegroups.com, uidl...@gmail.com
Hi Jason,

Dynamically setting the "signInSuccessUrl" is something we hope to make available within the next couple of weeks. In the mean time, you could save your destination URL into local or session storage before navigating to the sign in page.
Message has been deleted
Message has been deleted
Message has been deleted

Derek Salama

unread,
Jun 4, 2015, 11:23:57 AM6/4/15
to google-iden...@googlegroups.com, derek...@google.com, uidl...@gmail.com
Hi Jason, 

We just added a feature that should solve your problem.

It seems like you want to return the user back to the page where they tried to sign in and I am guessing the sign in page is variable.

In the sign in page when you initialize the signInButton, append the following to your configuration:
{
  widgetUrl: '/widget?signInSuccessUrl='+encodeURIComponent(window.location.href),
  ...
}

When the user tries to log in, it will take them to /widget?signInSuccessUrl=xxxxxxxxx&mode=select

After the user successfully logs in, it will take them back to the first page where the sign in flow started overriding the required signInSuccessUrl in the widget page configuration.

You can also modify the query parameter from the default value "signInSuccessUrl" by specifying it in the configuration on the widget page: queryParameterForSignInSuccessUrl: 'yourCustomSignInSuccessUrlQueryParameter'. If you do so, make sure you update the link in your sign in button config.

Hopefully that answers your question.

Jason Baik

unread,
Jun 6, 2015, 6:32:18 PM6/6/15
to google-iden...@googlegroups.com, uidl...@gmail.com
Thank you. 
It works :)

dan.cor...@gmail.com

unread,
Jul 10, 2015, 3:04:11 PM7/10/15
to google-iden...@googlegroups.com, uidl...@gmail.com
Hi Derek,

Would this flow still reach the Sign-in Success URL specified in the API CONFIGURATION tab before redirecting to the page where the signing flow started to allow these important steps to still happen: "This URL will need to validate the Google Identity Toolkit token and then begin an authenticated session however you see fit."?

Thanks,
dan

Derek Salama

unread,
Jul 13, 2015, 11:41:47 PM7/13/15
to google-iden...@googlegroups.com, dan.cor...@gmail.com, uidl...@gmail.com
Hi Dan,

This flow overrides the previously configured Sign-In Success URL

dan.cor...@gmail.com

unread,
Jul 14, 2015, 11:42:19 PM7/14/15
to google-iden...@googlegroups.com, uidl...@gmail.com, dan.cor...@gmail.com
On Monday, July 13, 2015 at 11:41:47 PM UTC-4, Derek Salama wrote:
Hi Dan,

This flow overrides the previously configured Sign-In Success URL

Rather unfortunate I'd say as this means the code for validating the token and initiating the authenticated session would need to be available/replicated in all (GAE) modules from which the authentication flow can originate.

Might I make an alternate suggestion for your consideration?

How about adding an optional config parameter for the signInButton, say originatingURL or something like that (or, better yet, automatically pick up the originating URI in the signInButton code?), which would simply be passed as a query parameter to the configured Sign-In Success URL: <signInSuccessUrl>?originatingURL=<originatingURL>, which would preserve the precisely localized token validation and session setup code as initially designed and also allow followup redirection to the originating URL from the app's code (if desired) - no change in the GIT flow.

The same method can also be applied to the Sign-out URL, allowing similar redirection from the app's code after it completes all tasks required for user signing out.

Thanks,
dan

Bassam Ojeil

unread,
Jul 15, 2015, 12:22:03 AM7/15/15
to google-iden...@googlegroups.com, uidl...@gmail.com, dan.cor...@gmail.com
Hey Dan,
I am not sure if I understood this correctly.
In the signInButton config, you could set the widgetUrl to the following:
widgetUrl: '/widget?signInSuccessUrl='+encodeURIComponent("constantSignInSuccessUrl?originatingUrl="+window.location.href),

Where constantSignInSuccessUrl is the fixed signInSuccessUrl in the widget page.

Then on success, you would get redirected to constantSignInSuccessUrl?originatingUrl=window.location.href
On that page after you do your processing, you can check if the originatingUrl is present and redirect there. In this case, whatever "window.location.href" evaluated to.

Hopefully this answers your question.

Best regards,
Bassam

--
You received this message because you are subscribed to the Google Groups "Google Identity Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-identity-t...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

dan.cor...@gmail.com

unread,
Jul 15, 2015, 12:29:28 AM7/15/15
to google-iden...@googlegroups.com, dan.cor...@gmail.com, uidl...@gmail.com
Nice, I'll give this a try!

Thanks a lot!
dan

dan.cor...@gmail.com

unread,
Jul 15, 2015, 11:55:43 PM7/15/15
to google-iden...@googlegroups.com, dan.cor...@gmail.com
Yes, it works wonderfully, for both Sign-In Success URL and Sign-out URL.

Thanks again,
dan
Reply all
Reply to author
Forward
0 new messages