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

checkAuth returning null when href target="_blank" #983

Closed
arshrp opened this issue Feb 23, 2021 · 8 comments
Closed

checkAuth returning null when href target="_blank" #983

arshrp opened this issue Feb 23, 2021 · 8 comments
Assignees
Labels

Comments

@arshrp
Copy link

arshrp commented Feb 23, 2021

Describe the bug
The OidcSecurityService.checkAuth() returns null when a tab is opened by clicking an href with target="_blank". Since storage=localstorage, it should return true, not null.

To Reproduce
Steps to reproduce the behavior:

  1. Edit the https://github.com/damienbod/angular-auth-oidc-client/blob/main/projects/sample-code-flow-auto-login/ sample
  2. In auth-config.module set storage: localstorage
  3. Add a link somewhere <a href="/" target="_blank">My Link</a>
  4. Start the app, login, then click the link.
  5. Notice the new tab opens and a loop ensues between authentication and autologin.

Expected behavior
Since storage is localstorage, the new tab should know we are authenticated and checkAuth() should return true.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Chrome
  • Version 87.0.4280.88 (Official Build) (64-bit)

Additional context
If the tab is opened by right click, "open link in new tab", it works (instead of regular left click).

I think the problem is the library thinks the new tab is a popup. From CheckAuthService:

    if (this.popupService.isCurrentlyInPopup()) {
        this.popupService.sendMessageToMainWindow(currentUrl);
        return of(null);
    }

But it probably shouldn't be doing this when storage=localstorage?

@FabianGosebrink
Copy link
Collaborator

Hey thanks, will talk to @damienbod and look into this.

@arshrp
Copy link
Author

arshrp commented Feb 24, 2021

Verified this bug occurs even with default storage setting (session).

Steps to reproduce are simple, just add <a href="\" target="_blank">Link</a> to angular-auth-oidc-client-main\projects\sample-code-flow-auto-login\src\app\home\home.component.html, start project, login and click link. Tab will open and get caught in repeated redirection to autologin (due to CheckAuthService code mentioned above).

@arshrp arshrp changed the title checkAuth returning null when href target="_blank" and storage=localstorage checkAuth returning null when href target="_blank" Feb 24, 2021
@FabianGosebrink
Copy link
Collaborator

Hey, I could not reproduce the issue the way you described. What I did was that I opened a "normal" popup via window.open(...) and with this I could reproduce the issue. Fixed this now in the PR mentioned above and added a button & link to open new popups. I am 99% sure this fixes your issue as I could not reproduce it the way you said.

@arshrp
Copy link
Author

arshrp commented Feb 28, 2021

Appreciate the quick fix. I'm surprised you could not reproduce, as all you have to do is add <a href="\" target="_blank">Link</a> to angular-auth-oidc-client-main\projects\sample-code-flow-auto-login\src\app\home\home.component.html, run npm run start-sample-code-flow-auto-login and click the link.

@FabianGosebrink
Copy link
Collaborator

FabianGosebrink commented Feb 28, 2021

Yeah but maybe we have different browser settings concerning to popups ;) Also I am wondering what a backslash as link should do as you mention a normal slash in the first post. But I got the idea I think. I think I could reproduce it and hopefully fixed it :-) You can test btw and let us know!

@arshrp
Copy link
Author

arshrp commented Feb 28, 2021

Verified the PR fixes the issue. Thanks for such a fast turnaround.

@arshrp arshrp closed this as completed Feb 28, 2021
@abdulfousan
Copy link

Above issue still happening for the sample-code-flow-auto-login project, list of changes i've made in sample below

home.component.html

<div>Welcome to home Route</div>

<br />
Is Authenticated: {{ isAuthenticated$ | async }}
<pre>{{ userData$ | async | json }}</pre>

<button (click)="openWindow()">Open normal popup</button>

home.component.ts

export class HomeComponent implements OnInit {
    userData$: Observable<any>;
    isAuthenticated$: Observable<boolean>;

    constructor(public oidcSecurityService: OidcSecurityService) {}

    ngOnInit() {
        this.isAuthenticated$ = this.oidcSecurityService.isAuthenticated$;
        this.userData$ = this.oidcSecurityService.userData$;
    }

    openWindow() {
        window.open('http://localhost:4200', '_blank');
    }
}

here localhost:4200 is another application having same clientId

@FabianGosebrink
Copy link
Collaborator

FabianGosebrink commented Mar 3, 2021

Hey @abdulfousan ,

if you open up a new window this is a completely new instance. You are not authenticated in there. You can add a AutoLoginGuard to be redirected to the sts automatically if you want.

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

3 participants