mirror of
https://github.com/zitadel/zitadel.git
synced 2025-02-28 20:47:22 +00:00
fix(console): update dependencies, force reauth on invalid token (#2267)
* fix: update oidc lib, force reauth * chore(console): deps (#2302) * cli core * cdk material * chore(deps-dev): bump @types/node from 15.12.2 to 16.7.6 in /console (#2284) Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 15.12.2 to 16.7.6. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump ts-node from 10.2.0 to 10.2.1 in /console (#2252) Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 10.2.0 to 10.2.1. - [Release notes](https://github.com/TypeStrong/ts-node/releases) - [Commits](https://github.com/TypeStrong/ts-node/compare/v10.2.0...v10.2.1) --- updated-dependencies: - dependency-name: ts-node dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * audit fix Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
parent
490cafa538
commit
33a2054be9
2791
console/package-lock.json
generated
2791
console/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -10,25 +10,25 @@
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "~12.2.0",
|
||||
"@angular/cdk": "~12.2.0",
|
||||
"@angular/common": "~12.2.0",
|
||||
"@angular/compiler": "~12.2.0",
|
||||
"@angular/core": "~12.2.0",
|
||||
"@angular/forms": "~12.2.0",
|
||||
"@angular/material": "^12.1.1",
|
||||
"@angular/material-moment-adapter": "^12.2.0",
|
||||
"@angular/platform-browser": "~12.2.0",
|
||||
"@angular/platform-browser-dynamic": "~12.2.0",
|
||||
"@angular/router": "~12.2.0",
|
||||
"@angular/service-worker": "~12.2.0",
|
||||
"@angular/animations": "~12.2.4",
|
||||
"@angular/cdk": "~12.2.4",
|
||||
"@angular/common": "~12.2.4",
|
||||
"@angular/compiler": "~12.2.4",
|
||||
"@angular/core": "~12.2.4",
|
||||
"@angular/forms": "~12.2.4",
|
||||
"@angular/material": "^12.2.4",
|
||||
"@angular/material-moment-adapter": "^12.2.4",
|
||||
"@angular/platform-browser": "~12.2.4",
|
||||
"@angular/platform-browser-dynamic": "~12.2.4",
|
||||
"@angular/router": "~12.2.4",
|
||||
"@angular/service-worker": "~12.2.4",
|
||||
"@grpc/grpc-js": "^1.3.2",
|
||||
"@ngx-translate/core": "^13.0.0",
|
||||
"@ngx-translate/http-loader": "^6.0.0",
|
||||
"@types/file-saver": "^2.0.2",
|
||||
"@types/google-protobuf": "^3.15.3",
|
||||
"@types/uuid": "^8.3.0",
|
||||
"angular-oauth2-oidc": "^10.0.3",
|
||||
"angular-oauth2-oidc": "^12.1.0",
|
||||
"angularx-qrcode": "^11.0.0",
|
||||
"cors": "^2.8.5",
|
||||
"file-saver": "^2.0.5",
|
||||
@ -48,13 +48,13 @@
|
||||
"zone.js": "~0.11.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "~12.1.1",
|
||||
"@angular/cli": "~12.2.0",
|
||||
"@angular/compiler-cli": "~12.2.0",
|
||||
"@angular/language-service": "~12.2.0",
|
||||
"@angular-devkit/build-angular": "~12.2.4",
|
||||
"@angular/cli": "~12.2.4",
|
||||
"@angular/compiler-cli": "~12.2.4",
|
||||
"@angular/language-service": "~12.2.4",
|
||||
"@types/jasmine": "~3.8.2",
|
||||
"@types/jasminewd2": "~2.0.10",
|
||||
"@types/node": "^15.12.1",
|
||||
"@types/node": "^16.7.6",
|
||||
"codelyzer": "^6.0.0",
|
||||
"jasmine-core": "~3.7.1",
|
||||
"jasmine-spec-reporter": "~7.0.0",
|
||||
@ -68,8 +68,8 @@
|
||||
"stylelint": "^13.10.0",
|
||||
"stylelint-config-standard": "^22.0.0",
|
||||
"stylelint-scss": "^3.20.1",
|
||||
"ts-node": "~10.2.0",
|
||||
"ts-node": "~10.2.1",
|
||||
"tslint": "~6.1.3",
|
||||
"typescript": "^4.2.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,62 +5,62 @@ import { BehaviorSubject, from, Observable } from 'rxjs';
|
||||
import { StatehandlerService } from './statehandler.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AuthenticationService {
|
||||
private authConfig!: AuthConfig;
|
||||
private _authenticated: boolean = false;
|
||||
private readonly _authenticationChanged: BehaviorSubject<
|
||||
boolean
|
||||
> = new BehaviorSubject(this.authenticated);
|
||||
private authConfig!: AuthConfig;
|
||||
private _authenticated: boolean = false;
|
||||
private readonly _authenticationChanged: BehaviorSubject<
|
||||
boolean
|
||||
> = new BehaviorSubject(this.authenticated);
|
||||
|
||||
constructor(
|
||||
private oauthService: OAuthService,
|
||||
private statehandler: StatehandlerService,
|
||||
) { }
|
||||
constructor(
|
||||
private oauthService: OAuthService,
|
||||
private statehandler: StatehandlerService,
|
||||
) { }
|
||||
|
||||
public initConfig(data: AuthConfig): void {
|
||||
this.authConfig = data;
|
||||
public initConfig(data: AuthConfig): void {
|
||||
this.authConfig = data;
|
||||
}
|
||||
|
||||
public get authenticated(): boolean {
|
||||
return this._authenticated;
|
||||
}
|
||||
|
||||
public get authenticationChanged(): Observable<boolean> {
|
||||
return this._authenticationChanged;
|
||||
}
|
||||
|
||||
public getOIDCUser(): Observable<any> {
|
||||
return from(this.oauthService.loadUserProfile());
|
||||
}
|
||||
|
||||
public async authenticate(
|
||||
partialConfig?: Partial<AuthConfig>,
|
||||
force: boolean = false,
|
||||
): Promise<boolean> {
|
||||
if (partialConfig) {
|
||||
Object.assign(this.authConfig, partialConfig);
|
||||
}
|
||||
this.oauthService.configure(this.authConfig);
|
||||
|
||||
public get authenticated(): boolean {
|
||||
return this._authenticated;
|
||||
this.oauthService.strictDiscoveryDocumentValidation = false;
|
||||
await this.oauthService.loadDiscoveryDocumentAndTryLogin();
|
||||
|
||||
this._authenticated = this.oauthService.hasValidAccessToken();
|
||||
if (!this.oauthService.hasValidIdToken() || !this.authenticated || partialConfig || force) {
|
||||
const newState = await this.statehandler.createState().toPromise();
|
||||
this.oauthService.initCodeFlow(newState);
|
||||
}
|
||||
this._authenticationChanged.next(this.authenticated);
|
||||
|
||||
public get authenticationChanged(): Observable<boolean> {
|
||||
return this._authenticationChanged;
|
||||
}
|
||||
return this.authenticated;
|
||||
}
|
||||
|
||||
public getOIDCUser(): Observable<any> {
|
||||
return from(this.oauthService.loadUserProfile());
|
||||
}
|
||||
|
||||
public async authenticate(
|
||||
partialConfig?: Partial<AuthConfig>,
|
||||
): Promise<boolean> {
|
||||
if (partialConfig) {
|
||||
Object.assign(this.authConfig, partialConfig);
|
||||
}
|
||||
this.oauthService.configure(this.authConfig);
|
||||
|
||||
this.oauthService.strictDiscoveryDocumentValidation = false;
|
||||
await this.oauthService.loadDiscoveryDocumentAndTryLogin();
|
||||
|
||||
this._authenticated = this.oauthService.hasValidAccessToken();
|
||||
|
||||
if (!this.oauthService.hasValidIdToken() || !this.authenticated || partialConfig) {
|
||||
const newState = await this.statehandler.createState().toPromise();
|
||||
this.oauthService.initCodeFlow(newState);
|
||||
}
|
||||
this._authenticationChanged.next(this.authenticated);
|
||||
|
||||
return this.authenticated;
|
||||
}
|
||||
|
||||
public signout(): void {
|
||||
this.oauthService.logOut();
|
||||
this._authenticated = false;
|
||||
this._authenticationChanged.next(false);
|
||||
}
|
||||
public signout(): void {
|
||||
this.oauthService.logOut();
|
||||
this._authenticated = false;
|
||||
this._authenticationChanged.next(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,52 +17,52 @@ const accessTokenStorageKey = 'access_token';
|
||||
* Set the authentication token
|
||||
*/
|
||||
export class AuthInterceptor<TReq = unknown, TResp = unknown> implements UnaryInterceptor<TReq, TResp> {
|
||||
public triggerDialog: Subject<boolean> = new Subject();
|
||||
constructor(
|
||||
private authenticationService: AuthenticationService,
|
||||
private storageService: StorageService,
|
||||
private dialog: MatDialog,
|
||||
) {
|
||||
this.triggerDialog.pipe(debounceTime(1000)).subscribe(() => {
|
||||
this.openDialog();
|
||||
});
|
||||
}
|
||||
public triggerDialog: Subject<boolean> = new Subject();
|
||||
constructor(
|
||||
private authenticationService: AuthenticationService,
|
||||
private storageService: StorageService,
|
||||
private dialog: MatDialog,
|
||||
) {
|
||||
this.triggerDialog.pipe(debounceTime(1000)).subscribe(() => {
|
||||
this.openDialog();
|
||||
});
|
||||
}
|
||||
|
||||
public async intercept(request: Request<TReq, TResp>, invoker: any): Promise<UnaryResponse<TReq, TResp>> {
|
||||
await this.authenticationService.authenticationChanged.pipe(
|
||||
filter((authed) => !!authed),
|
||||
first(),
|
||||
).toPromise();
|
||||
public async intercept(request: Request<TReq, TResp>, invoker: any): Promise<UnaryResponse<TReq, TResp>> {
|
||||
await this.authenticationService.authenticationChanged.pipe(
|
||||
filter((authed) => !!authed),
|
||||
first(),
|
||||
).toPromise();
|
||||
|
||||
const metadata = request.getMetadata();
|
||||
const accessToken = this.storageService.getItem(accessTokenStorageKey);
|
||||
metadata[authorizationKey] = `${bearerPrefix} ${accessToken}`;
|
||||
const metadata = request.getMetadata();
|
||||
const accessToken = this.storageService.getItem(accessTokenStorageKey);
|
||||
metadata[authorizationKey] = `${bearerPrefix} ${accessToken}`;
|
||||
|
||||
return invoker(request).then((response: any) => {
|
||||
return response;
|
||||
}).catch((error: any) => {
|
||||
if (error.code === 16) {
|
||||
this.triggerDialog.next(true);
|
||||
}
|
||||
return Promise.reject(error);
|
||||
});
|
||||
}
|
||||
return invoker(request).then((response: any) => {
|
||||
return response;
|
||||
}).catch((error: any) => {
|
||||
if (error.code === 16) {
|
||||
this.triggerDialog.next(true);
|
||||
}
|
||||
return Promise.reject(error);
|
||||
});
|
||||
}
|
||||
|
||||
private openDialog(): void {
|
||||
const dialogRef = this.dialog.open(WarnDialogComponent, {
|
||||
data: {
|
||||
confirmKey: 'ACTIONS.LOGIN',
|
||||
titleKey: 'ERRORS.TOKENINVALID.TITLE',
|
||||
descriptionKey: 'ERRORS.TOKENINVALID.DESCRIPTION',
|
||||
},
|
||||
disableClose: true,
|
||||
width: '400px',
|
||||
});
|
||||
private openDialog(): void {
|
||||
const dialogRef = this.dialog.open(WarnDialogComponent, {
|
||||
data: {
|
||||
confirmKey: 'ACTIONS.LOGIN',
|
||||
titleKey: 'ERRORS.TOKENINVALID.TITLE',
|
||||
descriptionKey: 'ERRORS.TOKENINVALID.DESCRIPTION',
|
||||
},
|
||||
disableClose: true,
|
||||
width: '400px',
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().pipe(take(1)).subscribe(resp => {
|
||||
if (resp) {
|
||||
this.authenticationService.authenticate(undefined);
|
||||
}
|
||||
});
|
||||
}
|
||||
dialogRef.afterClosed().pipe(take(1)).subscribe(resp => {
|
||||
if (resp) {
|
||||
this.authenticationService.authenticate(undefined, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user