Merge branch 'master' of gitlab.com:grassrootseconomics/cic-staff-client into bvander/refactor-registry-service

This commit is contained in:
Blair Vanderlugt 2021-06-12 09:59:31 -07:00
commit e7d9b6e442
9 changed files with 51 additions and 57 deletions

View File

@ -1,4 +1,3 @@
import { AuthService } from '@app/_services';
import { Injectable } from '@angular/core';
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
import { Observable } from 'rxjs';
@ -8,12 +7,11 @@ export class HttpConfigInterceptor implements HttpInterceptor {
constructor() {}
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
//const token: string = sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN'));
const token: string = AuthService.getSessionToken()
// const token: string = sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN'));
if (token) {
request = request.clone({headers: request.headers.set('Authorization', 'Bearer ' + token)});
}
// if (token) {
// request = request.clone({headers: request.headers.set('Authorization', 'Bearer ' + token)});
// }
return next.handle(request);
}

View File

@ -36,7 +36,7 @@ export class AuthService {
}
}
public static getSessionToken(): string {
getSessionToken(): string {
return sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN'));
}
@ -50,7 +50,7 @@ export class AuthService {
getWithToken(): Promise<boolean> {
const headers = {
Authorization: 'Bearer ' + AuthService.getSessionToken,
Authorization: 'Bearer ' + this.getSessionToken,
'Content-Type': 'application/json;charset=utf-8',
'x-cic-automerge': 'none',
};
@ -93,41 +93,41 @@ export class AuthService {
}
async login(): Promise<boolean> {
if (AuthService.getSessionToken()) {
if (this.getSessionToken()) {
sessionStorage.removeItem(btoa('CICADA_SESSION_TOKEN'));
}
const o = await this.getChallenge();
} else {
const o = await this.getChallenge();
const r = await signChallenge(
o.challenge,
o.realm,
environment.cicMetaUrl,
this.mutableKeyStore
);
const r = await signChallenge(
o.challenge,
o.realm,
environment.cicMetaUrl,
this.mutableKeyStore
);
const tokenResponse = await this.sendSignedChallenge(r)
.then(response => {
const token = response.headers.get('Token')
if (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
}
})
const tokenResponse = await this.sendSignedChallenge(r)
.then(response => {
const token = response.headers.get('Token')
if (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
if (tokenResponse) {
this.setSessionToken(tokenResponse);
this.setState('Click button to log in');
return true
}
return false
}
return false
}
loginView(): void {

View File

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { Settings } from '@app/_models';
import { TransactionHelper } from '@cicnet/cic-client';
import { TransactionHelper } from 'cic-client';
import { first } from 'rxjs/operators';
import { TransactionService } from '@app/_services/transaction.service';
import { environment } from '@src/environments/environment';

View File

@ -6,12 +6,6 @@ import { TokenRegistry, AccountIndex } from '@app/_eth';
import { HttpGetter } from '@app/_helpers';
import { Web3Service } from '@app/_services/web3.service';
//export interface RegistryCollection {
// cicRegistry: CICRegistry,
// tokenRegistry: TokenRegistry
//}
@Injectable({
providedIn: 'root',
})

View File

@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { CICRegistry } from '@cicnet/cic-client';
import { CICRegistry } from 'cic-client';
import { TokenRegistry } from '@app/_eth';
import { HttpClient } from '@angular/common/http';
import { RegistryService } from '@app/_services/registry.service';
@ -21,13 +21,12 @@ export class TokenService {
async init(): Promise<void> {
this.registry = await RegistryService.getRegistry();
this.tokenRegistry = await RegistryService.getTokenRegistry();
//this.registry.onload = async (address: string): Promise<void> => {
// this.tokenRegistry = new TokenRegistry(
// await this.registry.getContractAddressByName('TokenRegistry')
// );
// this.onload(this.tokenRegistry !== undefined);
//};
this.registry.onload = async (address: string): Promise<void> => {
this.tokenRegistry = new TokenRegistry(
await this.registry.getContractAddressByName('TokenRegistry')
);
this.onload(this.tokenRegistry !== undefined);
};
}
addToken(token: Token): void {

View File

@ -14,7 +14,7 @@ import { AuthService } from '@app/_services/auth.service';
import { defaultAccount } from '@app/_models';
import { LoggingService } from '@app/_services/logging.service';
import { HttpClient } from '@angular/common/http';
import { CICRegistry } from '@cicnet/cic-client';
import { CICRegistry } from 'cic-client';
import { RegistryService } from '@app/_services/registry.service';
import Web3 from 'web3';
import { Web3Service } from '@app/_services/web3.service';

View File

@ -10,7 +10,7 @@ import { TokenService } from '@app/_services/token.service';
import { AccountIndex } from '@app/_eth';
import { MutableKeyStore, PGPSigner, Signer } from '@app/_pgp';
import { RegistryService } from '@app/_services/registry.service';
import { CICRegistry } from '@cicnet/cic-client';
import { CICRegistry } from 'cic-client';
import { AuthService } from '@app/_services/auth.service';
import { personValidation, vcardValidation } from '@app/_helpers';
import { add0x } from '@src/assets/js/ethtx/dist/hex';
@ -43,7 +43,7 @@ export class UserService {
) {}
async init(): Promise<void> {
// await this.authService.init();
await this.authService.init();
await this.tokenService.init();
this.keystore = this.authService.mutableKeyStore;
this.signer = new PGPSigner(this.keystore);

View File

@ -29,6 +29,9 @@ export class AuthComponent implements OnInit {
this.keyForm = this.formBuilder.group({
key: ['', Validators.required],
});
if (this.authService.getPrivateKey()) {
this.authService.loginView();
}
}
get keyFormStub(): any {

View File

@ -6,7 +6,7 @@ export const environment = {
logLevel: NgxLoggerLevel.ERROR,
serverLogLevel: NgxLoggerLevel.OFF,
loggingUrl: 'http://localhost:8000',
cicMetaUrl: 'https://meta-auth.dev.grassrootseconomics.net',
cicMetaUrl: 'https://meta.dev.grassrootseconomics.net',
publicKeysUrl: 'https://dev.grassrootseconomics.net/.well-known/publickeys/',
cicCacheUrl: 'https://cache.dev.grassrootseconomics.net',
web3Provider: 'wss://bloxberg-ws.dev.grassrootseconomics.net',