Skip to content

Instantly share code, notes, and snippets.

@krishnaanaril
Created October 5, 2018 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishnaanaril/9a07c99efe7db86b8ede17d4177be303 to your computer and use it in GitHub Desktop.
Save krishnaanaril/9a07c99efe7db86b8ede17d4177be303 to your computer and use it in GitHub Desktop.
Azure Active Directory authentication library service
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, Subscriber, of } from 'rxjs';
import { switchMap, map } from 'rxjs/operators';
import { RequestOptions } from '@angular/http';
import { adal } from 'adal-angular';
import * as AuthenticationContext from 'adal-angular/lib/adal'
import { environment } from '../../environments/environment';
@Injectable({
providedIn: 'root'
})
export class AdalService {
private _config: adal.Config;
private _context: adal.AuthenticationContext;
constructor(private http: HttpClient) {
this._config = environment.adalConfig;
this._context = new AuthenticationContext(this._config);
}
get config(): adal.Config {
return this._config;
}
get context(): adal.AuthenticationContext {
return this._context;
}
get isLogged(): boolean {
const user = this._context.getCachedUser();
const token = this._context.getCachedToken(this._config.clientId);
return !!user && !!token;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment