Skip to content
Snippets Groups Projects
Commit c0d58c10 authored by Clayton, Brandon Scott's avatar Clayton, Brandon Scott
Browse files

add authorizer service.

parent 5b01aac7
No related branches found
No related tags found
1 merge request!538Internal Applications
import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {NshmpService, SpinnerService} from '@ghsc/nshmp-lib-ng/nshmp';
import {environment} from 'projects/nshmp-apps/src/environments/environment';
import {catchError, map} from 'rxjs';
interface AuthResponse {
isAuthorized: boolean;
}
/**
* Authorizer for USGS network.
*/
@Injectable({
providedIn: 'root',
})
export class AuthService {
private service = environment.webServices.aws;
private url = `${this.service.url}${this.service.services.auth}`;
constructor(
private http: HttpClient,
private spinnerService: SpinnerService,
private nshmpService: NshmpService
) {}
isAuthorized() {
const ref = this.spinnerService.show('Checking USGS network ...');
return this.http.get<AuthResponse>(this.url).pipe(
map(response => {
console.log(response);
ref.close();
if (!response.isAuthorized) {
this.nshmpService.throwError$(
new Error('Must be on USGS network to access internal applications')
);
}
return response.isAuthorized;
}),
catchError((error: Error) => {
ref.close();
return this.nshmpService.throwError$(error);
})
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment