Skip to content

Instantly share code, notes, and snippets.

@danielcrisp
Last active August 8, 2018 14:01
Show Gist options
  • Save danielcrisp/687407b64efee5b407ce34c7901d19df to your computer and use it in GitHub Desktop.
Save danielcrisp/687407b64efee5b407ce34c7901d19df to your computer and use it in GitHub Desktop.
AuthService - Async HTTP Interceptors with Angular 4
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();
}
}
@mikecabana
Copy link

Updated gist for ng 6.x and rxjs 6.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment