Lint changes from master.
This commit is contained in:
parent
157f88b052
commit
c0c94d3e2d
@ -35,7 +35,7 @@ export class AuthService {
|
|||||||
await this.mutableKeyStore.importPrivateKey(localStorage.getItem(btoa('CICADA_PRIVATE_KEY')));
|
await this.mutableKeyStore.importPrivateKey(localStorage.getItem(btoa('CICADA_PRIVATE_KEY')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getSessionToken(): string {
|
getSessionToken(): string {
|
||||||
return sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN'));
|
return sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN'));
|
||||||
}
|
}
|
||||||
@ -49,84 +49,80 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getWithToken(): Promise<boolean> {
|
getWithToken(): Promise<boolean> {
|
||||||
const headers = {
|
const headers = {
|
||||||
Authorization: 'Bearer ' + this.getSessionToken,
|
Authorization: 'Bearer ' + this.getSessionToken,
|
||||||
'Content-Type': 'application/json;charset=utf-8',
|
'Content-Type': 'application/json;charset=utf-8',
|
||||||
'x-cic-automerge': 'none',
|
'x-cic-automerge': 'none',
|
||||||
};
|
};
|
||||||
const options = {
|
const options = {
|
||||||
headers,
|
headers,
|
||||||
};
|
};
|
||||||
return fetch(environment.cicMetaUrl, options).then((response) => {
|
return fetch(environment.cicMetaUrl, options).then((response) => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
this.loggingService.sendErrorLevelMessage('failed to get with auth token.',
|
this.loggingService.sendErrorLevelMessage('failed to get with auth token.', this, {
|
||||||
this,
|
error: '',
|
||||||
{ error: "" });
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO rename to send signed challenge and set session. Also separate these responsibilities
|
// TODO rename to send signed challenge and set session. Also separate these responsibilities
|
||||||
sendSignedChallenge(hobaResponseEncoded: any): Promise<any> {
|
sendSignedChallenge(hobaResponseEncoded: any): Promise<any> {
|
||||||
const headers = {
|
const headers = {
|
||||||
Authorization: 'HOBA ' + hobaResponseEncoded,
|
Authorization: 'HOBA ' + hobaResponseEncoded,
|
||||||
'Content-Type': 'application/json;charset=utf-8',
|
'Content-Type': 'application/json;charset=utf-8',
|
||||||
'x-cic-automerge': 'none',
|
'x-cic-automerge': 'none',
|
||||||
};
|
};
|
||||||
const options = {
|
const options = {
|
||||||
headers,
|
headers,
|
||||||
};
|
};
|
||||||
return fetch(environment.cicMetaUrl, options)
|
return fetch(environment.cicMetaUrl, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
getChallenge(): Promise<any> {
|
getChallenge(): Promise<any> {
|
||||||
return fetch(environment.cicMetaUrl)
|
return fetch(environment.cicMetaUrl).then((response) => {
|
||||||
.then(response => {
|
if (response.status === 401) {
|
||||||
if (response.status === 401) {
|
const authHeader: string = response.headers.get('WWW-Authenticate');
|
||||||
const authHeader: string = response.headers.get('WWW-Authenticate');
|
return hobaParseChallengeHeader(authHeader);
|
||||||
return hobaParseChallengeHeader(authHeader);
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async login(): Promise<boolean> {
|
async login(): Promise<boolean> {
|
||||||
if (this.getSessionToken()) {
|
if (this.getSessionToken()) {
|
||||||
sessionStorage.removeItem(btoa('CICADA_SESSION_TOKEN'));
|
sessionStorage.removeItem(btoa('CICADA_SESSION_TOKEN'));
|
||||||
} else {
|
} else {
|
||||||
const o = await this.getChallenge();
|
const o = await this.getChallenge();
|
||||||
|
|
||||||
const r = await signChallenge(
|
const r = await signChallenge(
|
||||||
o.challenge,
|
o.challenge,
|
||||||
o.realm,
|
o.realm,
|
||||||
environment.cicMetaUrl,
|
environment.cicMetaUrl,
|
||||||
this.mutableKeyStore
|
this.mutableKeyStore
|
||||||
);
|
);
|
||||||
|
|
||||||
const tokenResponse = await this.sendSignedChallenge(r)
|
const tokenResponse = await this.sendSignedChallenge(r).then((response) => {
|
||||||
.then(response => {
|
const token = response.headers.get('Token');
|
||||||
const token = response.headers.get('Token')
|
if (token) {
|
||||||
if (token) {
|
return token;
|
||||||
return token
|
|
||||||
}
|
|
||||||
if (response.status === 401) {
|
|
||||||
let e = new HttpError("You are not authorized to use this system", response.status)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
if (!response.ok) {
|
|
||||||
let e = new HttpError("Unknown error from authentication server", response.status)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (tokenResponse) {
|
|
||||||
this.setSessionToken(tokenResponse);
|
|
||||||
this.setState('Click button to log in');
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
if (response.status === 401) {
|
||||||
|
throw new HttpError('You are not authorized to use this system', response.status);
|
||||||
|
}
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new HttpError('Unknown error from authentication server', response.status);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (tokenResponse) {
|
||||||
|
this.setSessionToken(tokenResponse);
|
||||||
|
this.setState('Click button to log in');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ export class AuthComponent implements OnInit {
|
|||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private errorDialogService: ErrorDialogService,
|
private errorDialogService: ErrorDialogService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async ngOnInit(): Promise<void> {
|
async ngOnInit(): Promise<void> {
|
||||||
@ -49,10 +49,10 @@ export class AuthComponent implements OnInit {
|
|||||||
|
|
||||||
async login(): Promise<void> {
|
async login(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const loginResult = await this.authService.login()
|
const loginResult = await this.authService.login();
|
||||||
if (loginResult) {
|
if (loginResult) {
|
||||||
this.router.navigate(['/home']);
|
this.router.navigate(['/home']);
|
||||||
}
|
}
|
||||||
} catch (HttpError) {
|
} catch (HttpError) {
|
||||||
this.errorDialogService.openDialog({
|
this.errorDialogService.openDialog({
|
||||||
message: HttpError.message,
|
message: HttpError.message,
|
||||||
|
Loading…
Reference in New Issue
Block a user