Summary Table

Categories Total Count
PII 0
URL 0
DNS 0
EKL 0
IP 0
PORT 0
VsID 0
CF 0
AI 0
VPD 0
PL 0
Other 0

File Content

import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Router } from '@angular/router';
import { Location } from '@angular/common';

import { UserInfoModel, SsoEncodedUrlsModel } from './auth.model';
import * as jwt from 'jsonwebtoken';
import { CanDeactivateGuard } from './../shared/guards/can-deactivate-gaurd';

// import 'rxjs/add/operator/map';

import { environment } from '../../environments/environment';
interface Ierror {
errorMsg: string;
errorStatus: boolean;
}
@Injectable()
export class AuthenticationService {
constructor(
private http: HttpClient,
private canDeactivateGuard: CanDeactivateGuard,
private router: Router,
private location: Location
) {}
error: Ierror = {
errorMsg: '',
errorStatus: false
};
authenticateAndGetUserInfo(userName) {
userName = encodeURIComponent(userName);
return this.http.get(
`${environment.nodeserver}/login/userRoles/${userName}`
);
}

getDropDownInfo() {
const headers = new HttpHeaders().set('Auth', 'false');
return this.http.get<Array<string>>(
`${environment.nodeserver}/login/login`,
{ headers: headers }
);
}
// test code for sso
ssoUrls(attachmentId?: string) {
console.log('ssoUrls loginService ', attachmentId);
const headers = new HttpHeaders().set('Auth', 'false');
if (attachmentId) {
const body = { attachmentId };
console.log('ssoUrls loginService inside if ', body);
return this.http.post<SsoEncodedUrlsModel>(
`${environment.nodeserver}/sso/ssoUrls`,
body,
{ headers: headers }
);
} else {
const body = {};
return this.http.post<SsoEncodedUrlsModel>(
`${environment.nodeserver}/sso/ssoUrls`,
body,
{ headers: headers }
);
}
}
getNtName(encodedUrls) {
const headers = new HttpHeaders().set('Auth', 'false');
// const options = {
// headers: new HttpHeaders({ 'Content-Type': 'application/json' })
// };
return this.http.post<string>(
`${environment.hacssoserver}`,
encodedUrls,
{ headers: headers }
// options
);
}
getUserInfo(user) {
return this.http.post<UserInfoModel>(
`${environment.nodeserver}/sso/getUserInfo`,
user
);
}
setErrorMsg(errorMsg: string, errorStatus: boolean) {
this.error.errorMsg = errorMsg;
this.error.errorStatus = errorStatus;
}
getErrorMsg() {
return new Observable<Ierror>(observer => {
observer.next(this.error);
});
}
getDecodedToken() {
if (sessionStorage.getItem('jwt')) {
const jwtToken = sessionStorage.getItem('jwt');
const decodedToken = jwt.decode(jwtToken);
return decodedToken;
} else {
return undefined;
}
}
getDecodedUserInfo() {
if (this.getDecodedToken()) {
const userInfo = this.getDecodedToken()['userInfo'];
return userInfo;
} else {
return undefined;
}
}
isTokenExpired(): boolean {
const exp = this.getDecodedToken()['exp'];
const now = Date.now() / 1000;
return exp < now;
}
// if (this.router.url !== '/rfaiAdmin') {
// sessionStorage.clear();
// } else {
logout() {
this.location.replaceState('/');
this.router.navigate(['/login']);
console.log('in logout', this.canDeactivateGuard.getCanLogout());
if (this.canDeactivateGuard.getCanLogout()) {
console.log('reached session clear in logout');
sessionStorage.clear();
} else {
return;
}
// }
}
}