5

My problem is I'm using auth0 as my authentication service, now when a user logs in and is authenticated it gets redirected back to my callback url which then decides where to send the user now my problem is when you get redirected back to your callback url from auth0 there are queryParams in the url string like so..

http://localhost:4200/account/login/callback#access_token="dsadsadsadsa dasdsaa" just as an example but then in a split second the query string is removed and its left at http://localhost:4200 now Im trying to grab the query Params using this method

this.activatedRoute.queryParams.subscribe(params => {
    console.log(params);
});

now this should work but the console.log is an empty object every time, I think its because of that url change that happens..

Is there some way I can grab the query params before that removal??

EDIT

Basically what is happening is I'm getting authenticated then I get redirected to

localhost:4200/account/login/callback?acessToken="dasdasdaefssves"

but then the route changes to

localhost:4200/account/login/callback

without the query parameters before the activatedRoute function gets a chance to run!

Any help would be appreciated!

8
  • i think you have to check in NavigationStart and NavigationEnd where your router is being captured simultaneously Commented May 17, 2018 at 6:12
  • @Sanoj_V not sure what you mean? Commented May 17, 2018 at 6:12
  • can you tell me what type of path you have set in your router. Commented May 17, 2018 at 6:19
  • Its all done via auth0 so you set a redirectUrl, which is http://localhost:4200/account/login/callback Commented May 17, 2018 at 6:20
  • have you tried same path different parameter url like this: /account/login/callback and /account/login/callback/:acessToken Commented May 17, 2018 at 6:27

2 Answers 2

0

Notice your redirect-url is http://localhost:4200/account/login/callback?access_token="dsadsadsadsa dasdsaa"

but angular routes it to localhost:4200/account/callback

NOTE

You don't have that /account/login/callback route defined in angular. But you have /account/callback route instead. Angular tries to resolve the route and redirects its to /account/callback without the queryParams.

Define the route in angular and your issue will be resolved.

Sign up to request clarification or add additional context in comments.

7 Comments

I declared the route like this /login/callback/:authInfo but now I keep getting redirected to base url? any ideas?
Please see updated question I had a typo in there, i actually meant to write /account/login/callback the whole time so this isnt the issue
If your auth service is redirecting to http://localhost:4200/account/login/callback?access_token="dsadsadsadsa dasdsaa" then you need to define a route in your angular project for account/login/callback because ?access_token="dsadsadsadsa dasdsaa" is a querystring.
yeah I understand that but I do actually have that route defined I just didnt type it properly in my question which has now been fixed
in the comment you wrote you declared a route /login/callback/:authInfo. I believe it should be login/callback instead.
|
-1

I didn't get your complete question but as much as I understand. You want to get query parameter from URL.

To get query parameter from URL You need to do this.

 constructor(private activatedRoute: ActivatedRoute){}

This is how you can get all the query params from URL.

this.activatedRoute.queryParamMap
                .map((params: Params) => params.params)
                .subscribe( (params) => {
                     if(params && params['access_token']){
                        console.log(params['access_token']);
                     }
                 });

1 Comment

Sorry no this isnt the question, basically what happens is the query parameters are on the url for 1s before they are removed so when this.activatedRoute runs there are no query parameters to grab which is why I keep getting back an empty object

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.