locked
Authentication using Anglar5 with Adal.js: Unabel to redirect to the component after login RRS feed

  • Question

  • In angular 5 application, we are using Adal libraries for the Microsoft login. I've already registered an APP and given reply url.

    following is the auth.service.ts

    import { Adal5HTTPService, Adal5Service } from 'adal-angular5';
    import { HttpClient, HttpHandler } from '@angular/common/http';
    import { Injectable } from '@angular/core';
    import { Observable } from 'rxjs/Observable';

    @Injectable()
    export class AuthService {

      private _user = null;
      private _config = {
        tenant: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        clientId: '5xxxxxxxxxxxxxxxxxxxxxxxxxx',
        redirectUri: "http://localhost:44327/auth-callback",
        postLogoutRedirectUri: "http://localhost:44327"
      }

      constructor(private _adal: Adal5Service) {
        this._adal.init(this._config);
      }

      public isLoggedIn(): boolean {
        return this._adal.userInfo.authenticated;
      }

      public signout(): void {
        this._adal.logOut();
      }

      public startAuthentication(): any {
        this._adal.login();
        console.log("logging");
      }

      public getName(): string {
        return this._user.profile.name;
      }

      public completeAuthentication(): void {
        console.log("Complete Auth");
        this._adal.handleWindowCallback();
        this._adal.getUser().subscribe(user => {
          this._user = user;
          console.log(this._adal.userInfo);
          var expireIn = user.profile.exp - new Date().getTime();
        });
      }
    }

    auth-callback components

     ngOnInit() {
        this._authService.completeAuthentication();
        setTimeout(() => {
          this._router.navigate(['/protected']);
        }, 200); 
      }            

    Routing is

    RouterModule.forRoot(
          [
            {
              path: '',
              children: []
            },
            {
              path: 'protected',
              component: ProtectedComponent,
              canActivate: [AuthGuardService]
            },
            { path: 'auth-callback', component: AuthCallbackComponent }

          ]

    Issue is, Im able to redirect to microsoft login page, after successful login the browser is trying to load auth-callback and then failing. Please find the attached screens

    Monday, December 30, 2019 5:08 PM

Answers

  • Might try asking for help over here.

    https://forums.asp.net/130.aspx

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    • Proposed as answer by Richard MuellerMVP Tuesday, December 31, 2019 2:19 PM
    • Marked as answer by pituachMVP Saturday, January 4, 2020 9:30 PM
    Tuesday, December 31, 2019 3:36 AM

All replies

  • Hi VaseemMD,

    Thank you for posting here.

    According to your description, I note that your question is related to angular 5 and Adal, so I have moved the thread to Where is the Forum For…? forum which can help you find the correct forum to go ask questions.

    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, December 31, 2019 1:28 AM
  • Might try asking for help over here.

    https://forums.asp.net/130.aspx

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    • Proposed as answer by Richard MuellerMVP Tuesday, December 31, 2019 2:19 PM
    • Marked as answer by pituachMVP Saturday, January 4, 2020 9:30 PM
    Tuesday, December 31, 2019 3:36 AM
  • Please provide the thread link so that I can followup
    Tuesday, December 31, 2019 8:50 AM