Skip to content

Instantly share code, notes, and snippets.

@mikecabana
Forked from danielcrisp/auth.service.ts
Last active August 8, 2018 13:58
Show Gist options
  • Save mikecabana/b152cedd7d3537819b824ff3108aa23a to your computer and use it in GitHub Desktop.
Save mikecabana/b152cedd7d3537819b824ff3108aa23a to your computer and use it in GitHub Desktop.
Oidc Client Authorization Service - Async HTTP Interceptors | Angular 6.x | rxjs 6.x
import { Injectable } from '@angular/core';
import { UserManager, User } from 'oidc-client';
import { Observable, from } from 'rxjs';
@Injectable({
providedin: 'root'
})
export class AuthService {
private userManager: UserManager;
constructor () {
this.userManager = new UserManager({
// options
});
}
getUser(): Observable<User> {
// change the promise retruned from this.userManager.getUser() into an observable and return it
return from(this.userManager.getUser());
}
// TODO - perform other UserMananger tasks i.e. singinSilent, signinRedirect, or signoutRedirect.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment