Last active
August 8, 2018 14:01
-
-
Save danielcrisp/687407b64efee5b407ce34c7901d19df to your computer and use it in GitHub Desktop.
AuthService - Async HTTP Interceptors with Angular 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { UserManager, User } from 'oidc-client'; | |
import { Observable } from 'rxjs/Observable'; | |
import 'rxjs/add/observable/fromPromise'; | |
@Injectable() | |
export class AuthService { | |
private userManager: UserManager; | |
constructor () { | |
this.userManager = new UserManager({ | |
// options | |
}); | |
} | |
getUser (): Promise<User> { | |
return Observable.fromPromise(this.userManager.getUser()); | |
} | |
// new | |
login () { | |
// redirect user to login page | |
this.userManager.signinRedirect(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated gist for ng 6.x and rxjs 6.x