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

$location.search() problems #32

Closed
markusklooth opened this issue Sep 9, 2014 · 6 comments
Closed

$location.search() problems #32

markusklooth opened this issue Sep 9, 2014 · 6 comments

Comments

@markusklooth
Copy link

The usage of $location.search() within the validateUser function is unreliable, if you have $locationProvider.html5Mode equals false which is most likely the case if you are using the ionic framework.

For instance:
When clicking on the confirmation button, the browser is redirected to the following url:
http://localhost:8100/?account_confirmation_success=true &client_id=[client_id] &expiry=[expiry] &token=[token] &uid=[uid]
Inside the validateUser function, the following will always return undefined

if ($location.search().token !== void 0)  // Will always return undefined

since $location.search() will return an empty object.
See angular/angular.js#7239 for more information

@lynndylanhurley
Copy link
Owner

@markusklooth - I have had trouble with this in the past. My approach has been to work around the problem on the server-side, ensuring that the generated URL is something that angular understands. Will this approach work for you, or do you have another suggestion?

@markusklooth
Copy link
Author

Could we do something like this?

getParamByName: function(name) {
   // Check if param is set in url#hash
    if($location.search()[name] !== void 0) { return $location.seach()[name]; }
   // Otherwise check url params
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? void 0 : decodeURIComponent(results[1].replace(/\+/g, " "));
}

And then call getParamByName("token") and the other ones like this?

@markusklooth
Copy link
Author

I came up with the following solution:
In my $authProvider.configure I set the following option: confirmationSuccessUrl: <CLIENT_URL>/#/. Note the "/" after the "#". Without it $location.search() won't work.
Since I'm also using the rails devise_token gem, the confirmation url will look like this:
<CLIENT_URL>/#/?account_confirmation_success=true&token=<TOKEN>&client_id=<CLIENT_ID>

@lynndylanhurley
Copy link
Owner

@markusklooth - I'm reluctant to implement a custom URL parser if angularjs itself can't get it right.

I have several concerns here:

  • We will need to include tests for every possible permutation of anchors, hash-bangs, etc.
  • It's almost impossible to write tests for window.location. The $location service provides a mock service for testing.
  • We will need to strip the querystring after authentication while preserving the existing anchors, hash-bangs, etc. The $location service has a means to do this, and I would prefer to leverage that if possible

And if we were actually able to solve the problem, it would be better to push the fix upstream to angular.

I'm going to fix the issue server-side for now.

@lynndylanhurley
Copy link
Owner

I just saw your latest comment. I'm going to implement something like that on the server.

@lynndylanhurley
Copy link
Owner

@markusklooth - I think this is fixed in devise_token_auth version 0.1.28.beta4 - please check it out and let me know if it works for you.

nbrustein pushed a commit to nbrustein/ng-token-auth that referenced this issue May 27, 2015
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