File

src/lib/kiewit-authentication/kiewit-authentication.service.ts

Index

Properties
Methods

Constructor

constructor(service: Adal4Service, http: Adal4HTTPService)
Parameters :
Name Type Optional Description
service Adal4Service
http Adal4HTTPService

Methods

Public getToken
getToken()
Returns : any
Public getUser
getUser()
Returns : any
Public isAuthorized
isAuthorized()
Returns : any
Public logout
logout()
Returns : void
Public lolo
lolo()
Returns : void

Properties

Private adalConfig
adalConfig:
Private userProfile
userProfile: any
Type : any
import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';
import { Adal4Service, Adal4HTTPService } from 'adal-angular4';
//import { Client } from '@microsoft/microsoft-graph-client';
import { Observable } from 'rxjs/Rx';

@Injectable()
export class KiewitAuthenticationService {

    //private graphClient: Client;
    private userProfile: any;

    private adalConfig = {
        instance: 'https://login.windows.net/',
        tenant: environment.tenant,
        clientId: environment.clientId,
        redirectUri: window.location.origin + '/'//,
        //, extraQueryParameter: 'scope=offline_access%20User.Read%20Basic.All'
        , endpoints: {
            graphApiUri: "https://graph.windows.net"
        },        
        //postLogoutRedirectUri: window.location.origin + '/'
    };

    constructor(private service: Adal4Service, private http: Adal4HTTPService) {

        this.service.init(this.adalConfig);       

        // Handle callback if this is a redirect from Azure
        this.service.handleWindowCallback();

        //var cachedToken = this.service.getCachedToken(environment.clientId);
        //if (cachedToken) {

        ////    //console.log('cached token: ' + cachedToken);
        //    this.service.acquireToken(this.adalConfig.endpoints.graphApiUri)
        //        .subscribe((token) => {
        //            //this.graphClient = Client.init({
        //            //    authProvider: (done) => {
        //            //        done(undefined, token);
        //            //    }
        //            //});
        //            //console.log('The token: ' + token);

        //        }, (error) => {
        //            console.log('Error from acquire token call: ' + error);
        //        });
        //}      

        // Check if the user is authenticated. If not, call the login() method
        if (!this.service.userInfo.authenticated) {
            this.service.login();
        }
    }

    public getToken() {
        return this.service.userInfo.token;
    }

    public getUser() {
        return this.service.userInfo;
    }

    public isAuthorized() {
        return this.service.userInfo.authenticated;
    }

    public lolo() {
        //uri: string = ''

        //this.graphClient.api('/me').get().then((value) => {
        //    this.userProfile = value;
        //}).catch((error) => {
        //    console.log('Error from api call: ' + error);
        //});
    }

    // Logout Method
    public logout() {
        this.service.logOut();
    }
}

results matching ""

    No results matching ""