1

I have implemented Angular 2 Multi tenant application. I'm able to logout for the active Directory by using below method

    logout() {
    this.context.logOut();
    }

But now i have to implement logout active directory user without going to Microsoft logout page.The Active Directory user logout with out going to logout page like below Image.

enter image description here

User logout not like above image.I don't want to use the built in logout function.I have tried like below two different methods

           this.context.clearCacheForResource(this.userInfo.userName);
           this.context.clearCache();

But it's not clear the user information. when i'm clear the cache of the browser it's working.

Any Answer Appreciated.

Thanks in Advance........!

Balaraju Polaki
  • 133
  • 1
  • 15

3 Answers3

2

Your methods only clear local the cache/storage , it won't clear any session/cookie hold on azure ad, silent auth might be happening due to cookie is still there .If you want to clear that, then the built in logout should be the one to use.

Here is a similar thread and provides the workaround to implement the silent logout :

You could probably try to implement the silent logout(probably using iframe, this will prevent the ux from displaying), and then call clearCache to clear the localstorage/sessionstorage

Nan Yu
  • 26,101
  • 9
  • 68
  • 148
2

I have solved this by using like below code

import { SafeResourceUrl, DomSanitizer } from '@angular/platform-browser';

@Component({


selector: 'auth-container',

template: <iframe class="embed-responsive-item" *ngIf="show" width="0" height="0" [src]="url" allowfullscreen></iframe>,})

export class Auth implements OnInit {

public show = false;

constructor(private sanitizer: DomSanitizer) {
this.url = sanitizer.bypassSecurityTrustResourceUrl('https://login.microsoftonline.com/common/oauth2/logout?post_logout_redirect_uri=' + window.location.origin);  }}

here i'm hidding and showing iframe based on requirement.

Thanks @Nan

Balaraju Polaki
  • 133
  • 1
  • 15
0

I just had the same problem and it took me some time to find the answer in MSAL.js documentation:

export class AuthenticationService {
  constructor(
    private msalService: MsalService,
  ) { }

  logoutWithoutRedirect(): void {
    this.msalService.logoutRedirect({
      // Return false if you would like to stop navigation after local logout
      onRedirectNavigate: () => false
    })
  }
}
Rustam
  • 448
  • 6
  • 10