feat(console): grpc web interceptors, cleanup services (#631)

* managementservice, authservice, change all refs

* refactor grpc auth

* fix references

* interceptor logic

* new interceptor

* appinitializers, environment loader, interceptors

* remove circular dep

* init authconfig in grpc service

* authconfig

* lint

* update mgmt service

* fix references

* update clientid, fix interceptor

* rm unused authconfig

* todo auth interceptor
This commit is contained in:
Max Peintner
2020-08-29 10:43:35 +02:00
committed by GitHub
parent 40b8faaddd
commit eeea1f1c4b
81 changed files with 1877 additions and 2639 deletions

View File

@@ -1,21 +1,20 @@
import { PlatformLocation } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AuthConfig } from 'angular-oauth2-oidc';
import { AdminServicePromiseClient } from '../proto/generated/admin_grpc_web_pb';
import { AuthServicePromiseClient } from '../proto/generated/auth_grpc_web_pb';
import { ManagementServicePromiseClient } from '../proto/generated/management_grpc_web_pb';
import { GrpcRequestFn } from './grpc-handler';
import { AuthenticationService } from './authentication.service';
import { AuthInterceptor } from './interceptors/auth.interceptor';
import { OrgInterceptor } from './interceptors/org.interceptor';
import { StorageService } from './storage.service';
@Injectable({
providedIn: 'root',
})
export class GrpcService {
public issuer: string = '';
public clientid: string = '';
public redirectUri: string = '';
public postLogoutRedirectUri: string = '';
public auth!: AuthServicePromiseClient;
public mgmt!: ManagementServicePromiseClient;
public admin!: AdminServicePromiseClient;
@@ -23,22 +22,51 @@ export class GrpcService {
constructor(
private http: HttpClient,
private platformLocation: PlatformLocation,
private authenticationService: AuthenticationService,
private storageService: StorageService,
) { }
public async loadAppEnvironment(): Promise<any> {
return this.http.get('./assets/environment.json')
.toPromise().then((data: any) => {
if (data && data.authServiceUrl && data.mgmtServiceUrl && data.issuer) {
this.auth = new AuthServicePromiseClient(data.authServiceUrl);
this.mgmt = new ManagementServicePromiseClient(data.mgmtServiceUrl);
this.admin = new AdminServicePromiseClient(data.adminServiceUrl);
const interceptors = {
'unaryInterceptors': [
new AuthInterceptor(this.authenticationService, this.storageService),
new OrgInterceptor(this.storageService),
],
};
this.issuer = data.issuer;
if (data.clientid) {
this.clientid = data.clientid;
this.redirectUri = window.location.origin + this.platformLocation.getBaseHrefFromDOM() + 'auth/callback';
this.postLogoutRedirectUri = window.location.origin + this.platformLocation.getBaseHrefFromDOM() + 'signedout';
}
this.auth = new AuthServicePromiseClient(
data.authServiceUrl,
null,
// @ts-ignore
interceptors,
);
this.mgmt = new ManagementServicePromiseClient(
data.mgmtServiceUrl,
null,
// @ts-ignore
interceptors,
);
this.admin = new AdminServicePromiseClient(
data.adminServiceUrl,
null,
// @ts-ignore
interceptors,
);
const authConfig: AuthConfig = {
scope: 'openid profile email',
responseType: 'code',
oidc: true,
clientId: data.clientid,
issuer: data.issuer,
redirectUri: window.location.origin + this.platformLocation.getBaseHrefFromDOM() + 'auth/callback',
postLogoutRedirectUri: window.location.origin + this.platformLocation.getBaseHrefFromDOM() + 'signedout',
};
this.authenticationService.initConfig(authConfig);
}
return Promise.resolve(data);
}).catch(() => {
@@ -46,9 +74,3 @@ export class GrpcService {
});
}
}
export type RequestFactory<TClient, TReq, TResp> = (
client: TClient,
) => GrpcRequestFn<TReq, TResp>;
export type ResponseMapper<TResp, TMappedResp> = (resp: TResp) => TMappedResp;