import { Inject , Injectable } from '@angular/core' ; import { OAuthService } from 'angular-oauth2-oidc' ; import { HttpClient , HttpHeaders , HttpParams } from '@angular/common/http' ; import { environment } from '@env/environment' ; @ Injectable ( ) export class ROPCService { constructor ( private httpClient , private oauthService ) { } async login ( username , password ) { const profile = await this . oauthService . fetchTokenUsingPasswordFlowAndLoadUserProfile ( username , password ) ; return profile ; } logOut ( ) { if ( this . oauthService . getRefreshToken ( ) === null ) { return ; } const refreshToken = this . oauthService . getRefreshToken ( ) ; this . oauthService . logOut ( true ) ; const body = new HttpParams ( ) . set ( 'client_id' , this . oauthService . clientId ) . set ( 'refresh_token' , refreshToken ) ; return this . httpClient . post ( this . oauthService . logoutUrl , body . toString ( ) , { headers : new HttpHeaders ( ) . set ( 'Content-Type' , 'application/x-www-form-urlencoded' ) , } ) ; } }