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

Dynamic callback URL? #192

Closed
bavey opened this issue Nov 18, 2014 · 13 comments
Closed

Dynamic callback URL? #192

bavey opened this issue Nov 18, 2014 · 13 comments
Labels

Comments

@bavey
Copy link

bavey commented Nov 18, 2014

My app does not have a consistent login page such as http://example.com/login. Rather my app's URLs are dynamic and token based, for example: http://example.com/XH12aT1771. My login box consists of a modal overlaid on top of this dynamic-type page.

Is it possible for me to avoid redirecting a user to a static callback url upon authenticating, such as http://example.com/success? The problem with redirecting a user to a static callback url is it's a poor user experience as it takes the user away from the page they're on.

Are there any other solutions to avoid redirecting the user such as presenting a popup window?

@Guiiks
Copy link

Guiiks commented Nov 18, 2014

Hello,
I've exactly the same problem, trying to pass some dynamics variables on

            $scope.authenticate = function(provider) {
                $auth.authenticate(provider);
            };

Is there a trick to do it?
Thanks

@bavey
Copy link
Author

bavey commented Nov 19, 2014

Hi @Guiiks,

I've done some research concerning dynamic callback URLs with OAuth and it seems like really the only way to avoid redirecting the user away from the current page they log-in on is to have the entire OAuth experience take place in a JavaScript pop-up window. This post seems to cover the topic: http://stackoverflow.com/questions/1878529/twitter-oauth-via-a-popup

I would love to know if anybody else has any other ideas or solutions or can at least further expand on the JavaScript pop-up approach.

Thank you

@sahat
Copy link
Owner

sahat commented Nov 19, 2014

@Guiiks I will take a look at this issue in more detail later this week and try to come up with some solution.

@bavey
Copy link
Author

bavey commented Nov 19, 2014

hi @sahat, do you happen to have any insight on the dynamic callback situation or does it definitely have to be a hardcoded static url? any other ideas for how to solve the problem? thanks

@sahat
Copy link
Owner

sahat commented Nov 20, 2014

I don't think it has to be hard-coded @bhousman. With the current implementation callback is assigned during config phase. However it should be possible to change redirectUri at runtime with a few modifications to Satellizer.

The authorization endpoint with client code, redirect url, scope, etc is not generated after you click on the login button anyway. E.g. https://www.facebook.com/dialog/oauth?scope=foo&client_id=bar&redirect_url=xyz

@bavey
Copy link
Author

bavey commented Nov 20, 2014

@sahat the different social login providers (FB, Twitter, Google) are all requiring I enter a callback URL in their respective developer consoles -- wouldn't changing the redirect URI conflict with what I have set in those sites as they have to match?

@chrishawn
Copy link

I would like this as well. i am looking to do something on the fly like

$auth.authenticate('myOauthProvider',{redirectUri: window.location.href}).then(){}

and have that redirectUri override the one i put in the config setup

@bavey
Copy link
Author

bavey commented Dec 1, 2014

@chrishawn exactly what i'm looking for 👍

@sahat
Copy link
Owner

sahat commented Dec 2, 2014

I think I understand what you are trying to do. You might be refering to the route redirect rather than callback url you set during the configuration step via $authProvider.

The redirectUri is only relevant to the popup. As soon as it closes you can redirect to whatever route you want.

Let's say a user visits http://example.com/XH12aT1771 and clicks on Sign in with a Provider. Satellizer by default uses the hostname as the redirectUri for each provider:

redirectUri: window.location.origin // will simply be http://example.com

That's where Provider will redirect back inside this popup with an authorization code (or access_token if you are using implicit grant) as part of the query string parameter. It then exchanges that code for JWT and popup is usually closed before you can blink an eye.

After that it's up to you what you'd like to do next. By default after signing up it will redirect to /#/login and after logging in it will redirect to /#/ home page.

If you do not wish to redirect then set $authProvider.loginRedirect = null (or false) and then manually redirect to some other route:

 $auth.authenticate('myOauthProvider',).then() {
   $location.path('/' + uniqueId);
}

Hopefully that answers your question assuming I understood it correctly?

@sahat sahat added the question label Dec 2, 2014
@bavey
Copy link
Author

bavey commented Dec 2, 2014

@sahat Thanks for the suggestion. Let me try this and I will report back with my findings. Best Regards.

@bavey
Copy link
Author

bavey commented Jan 14, 2015

@sahat Excellent solution. Works great. Thank you.

@sahat
Copy link
Owner

sahat commented Jan 14, 2015

Cheers. Closing this issue.

@sahat sahat closed this as completed Jan 14, 2015
@jgentes
Copy link

jgentes commented Aug 16, 2015

Thanks, this config setting solved a problem for me too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants