question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I implement "redirect to where it come" mode ?

See original GitHub issue

from http://angularapp.com/abc/def , redirect to authentication server http://myauth.com/<authorization_endpoint> after login redirect back to http://angularapp.com/spa-callbak
I hope that this url have previous url as querystring like http://angularapp.com/spa-callbak?returnurl=/abc/def so I can perform a redirect.

Am I use this lib incorrectly ? I have flow issues for now:

  1. url /spa-callback is a compontent that have “this.router.navigate([”/“]);” inside ngOnInit() but only get 50% change to automatice goto ~/
  2. a component show’s user’s name , but some time there no value

my authentication server is IdentityServer4, to load user data i put this line in AppModule

this.oauthService.configure(authConfig);
        this.oauthService.tokenValidationHandler = new JwksValidationHandler();
        this.oauthService.loadDiscoveryDocumentAndLogin()
            .then(x => {
                if (x) {
                    this.oauthService.loadUserProfile();
                }
            });

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
John0Kingcommented, Sep 22, 2018

@jeroenheijmans I’m sorry for my bad english and Happy Mid-autumn festival 😄
I will try again with your solution after the holiday . and meantime I will close this issue.

0reactions
John0Kingcommented, Sep 26, 2018

@jeroenheijmans I tryed your solution , I have a suggestion about loadDiscoveryDocumentAndLogin(), I hope that this method save the url by default , and

this.oauthService.initImplicitFlow(encodeURIComponent(targetUrl || this.router.url));
// abouve code  this.router.url doesn't work, it always point to `/`

I used `(from @angular/common)Location.path(true)` to get current url

this is my final code :

this.oauthService.configure(authConfig);
        this.oauthService.tokenValidationHandler = new JwksValidationHandler();
        this.oauthService.loadDiscoveryDocument()
            .then(doc => {
                this.oauthService.tryLogin({
                    onTokenReceived: (context) => {
                        console.log("token received");
                        this.oauthService.loadUserProfile()
                            .then(cliams => {
                                console.log("profile loaded")
                                let preUrl = this.oauthService.state;
                                console.log("state:" + typeof (preUrl) + ":" + preUrl);
                                if (preUrl == null || preUrl == "") {
                                    preUrl = "/"
                                }
                                console.log("navigate to " + preUrl + ".....");
                                this.router.navigateByUrl(preUrl)
                                console.log("navigateed");

                            });
                    }
                })
                    .then(() => {
                        if (!this.oauthService.hasValidAccessToken()) {
                            let currentUrl = this._location.path(true);
                            console.log("initImplicit with :" + currentUrl);
                            this.oauthService.initImplicitFlow(currentUrl);
                        }
                    })
            });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Redirections in HTTP - MDN Web Docs - Mozilla
In HTTP, redirection is triggered by a server sending a special redirect response to a request. Redirect responses have status codes that start ......
Read more >
HTTP redirect codes for SEO explained - ContentKing
The HTTP redirect code, redirect for short, is a way to forward visitors and search engines from one URL to another. Redirects are...
Read more >
How to redirect sites to IE Mode in Edge browser - YouTube
Hi Guys,In this Video i have tried to explain about How to redirect sites to IE Mode in Edge browser step by step...
Read more >
Deploy Folder Redirection with Offline Files - Microsoft Learn
Enter the names of the users or groups to which you want to deploy Folder Redirection, select OK, and then select OK again....
Read more >
How to Set Up Redirections? - Rank Math
HTTP redirects are incredibly important in SEO & UX. When you visit a URL with a redirection, your browser automatically jumps to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found