mirror of
https://github.com/zitadel/zitadel.git
synced 2025-05-30 07:18:22 +00:00

* cli, core * cli, core * material, cdk * chore(deps-dev): bump @types/node from 18.13.0 to 18.15.11 in /console (#5594) Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 18.13.0 to 18.15.11. - [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-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump jasmine-core from 4.5.0 to 4.6.0 in /console (#5592) Bumps [jasmine-core](https://github.com/jasmine/jasmine) from 4.5.0 to 4.6.0. - [Release notes](https://github.com/jasmine/jasmine/releases) - [Changelog](https://github.com/jasmine/jasmine/blob/main/RELEASE.md) - [Commits](https://github.com/jasmine/jasmine/compare/v4.5.0...v4.6.0) --- updated-dependencies: - dependency-name: jasmine-core dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump zone.js from 0.12.0 to 0.13.0 in /console (#5586) Bumps [zone.js](https://github.com/angular/angular/tree/HEAD/packages/zone.js) from 0.12.0 to 0.13.0. - [Release notes](https://github.com/angular/angular/releases) - [Changelog](https://github.com/angular/angular/blob/main/packages/zone.js/CHANGELOG.md) - [Commits](https://github.com/angular/angular/commits/zone.js-0.13.0/packages/zone.js) --- updated-dependencies: - dependency-name: zone.js dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump prettier from 2.8.4 to 2.8.7 in /console (#5589) Bumps [prettier](https://github.com/prettier/prettier) from 2.8.4 to 2.8.7. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/2.8.4...2.8.7) --- updated-dependencies: - dependency-name: prettier 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> * lock * tsconfig, index signature, angular.json * cli core * material cdk * chore(deps): bump libphonenumber-js from 1.10.19 to 1.10.24 in /console (#5498) Bumps [libphonenumber-js](https://gitlab.com/catamphetamine/libphonenumber-js) from 1.10.19 to 1.10.24. - [Release notes](https://gitlab.com/catamphetamine/libphonenumber-js/tags) - [Changelog](https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/CHANGELOG.md) - [Commits](https://gitlab.com/catamphetamine/libphonenumber-js/compare/v1.10.19...v1.10.24) --- updated-dependencies: - dependency-name: libphonenumber-js dependency-type: direct:production 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> * update packages * rm redundant bindings * disable button * rm provider service * rm environment.tss * seo * fresh lock * eslint * eslint * increase budgets --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
267 lines
8.2 KiB
TypeScript
267 lines
8.2 KiB
TypeScript
import { COMMA, ENTER, SPACE } from '@angular/cdk/keycodes';
|
|
import { Location } from '@angular/common';
|
|
import { Component, Injector, Type } from '@angular/core';
|
|
import { AbstractControl, FormControl, FormGroup } from '@angular/forms';
|
|
import { MatLegacyChipInputEvent as MatChipInputEvent } from '@angular/material/legacy-chips';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
import { take } from 'rxjs';
|
|
import {
|
|
AddGoogleProviderRequest as AdminAddGoogleProviderRequest,
|
|
GetProviderByIDRequest as AdminGetProviderByIDRequest,
|
|
UpdateGoogleProviderRequest as AdminUpdateGoogleProviderRequest,
|
|
} from 'src/app/proto/generated/zitadel/admin_pb';
|
|
import { Options, Provider } from 'src/app/proto/generated/zitadel/idp_pb';
|
|
import {
|
|
AddGoogleProviderRequest as MgmtAddGoogleProviderRequest,
|
|
GetProviderByIDRequest as MgmtGetProviderByIDRequest,
|
|
UpdateGoogleProviderRequest as MgmtUpdateGoogleProviderRequest,
|
|
} from 'src/app/proto/generated/zitadel/management_pb';
|
|
import { AdminService } from 'src/app/services/admin.service';
|
|
import { Breadcrumb, BreadcrumbService, BreadcrumbType } from 'src/app/services/breadcrumb.service';
|
|
import { GrpcAuthService } from 'src/app/services/grpc-auth.service';
|
|
import { ManagementService } from 'src/app/services/mgmt.service';
|
|
import { ToastService } from 'src/app/services/toast.service';
|
|
import { requiredValidator } from '../../form-field/validators/validators';
|
|
|
|
import { PolicyComponentServiceType } from '../../policies/policy-component-types.enum';
|
|
|
|
@Component({
|
|
selector: 'cnsl-provider-google',
|
|
templateUrl: './provider-google.component.html',
|
|
})
|
|
export class ProviderGoogleComponent {
|
|
public showOptional: boolean = false;
|
|
public options: Options = new Options().setIsCreationAllowed(true).setIsLinkingAllowed(true);
|
|
public id: string | null = '';
|
|
public serviceType: PolicyComponentServiceType = PolicyComponentServiceType.MGMT;
|
|
private service!: ManagementService | AdminService;
|
|
|
|
public readonly separatorKeysCodes: number[] = [ENTER, COMMA, SPACE];
|
|
|
|
public form!: FormGroup;
|
|
|
|
public loading: boolean = false;
|
|
|
|
public provider?: Provider.AsObject;
|
|
public updateClientSecret: boolean = false;
|
|
|
|
constructor(
|
|
private authService: GrpcAuthService,
|
|
private route: ActivatedRoute,
|
|
private toast: ToastService,
|
|
private injector: Injector,
|
|
private _location: Location,
|
|
private breadcrumbService: BreadcrumbService,
|
|
) {
|
|
this.form = new FormGroup({
|
|
name: new FormControl('', []),
|
|
clientId: new FormControl('', [requiredValidator]),
|
|
clientSecret: new FormControl('', [requiredValidator]),
|
|
scopesList: new FormControl(['openid', 'profile', 'email'], []),
|
|
});
|
|
|
|
this.authService
|
|
.isAllowed(
|
|
this.serviceType === PolicyComponentServiceType.ADMIN
|
|
? ['iam.idp.write']
|
|
: this.serviceType === PolicyComponentServiceType.MGMT
|
|
? ['org.idp.write']
|
|
: [],
|
|
)
|
|
.pipe(take(1))
|
|
.subscribe((allowed) => {
|
|
if (allowed) {
|
|
this.form.enable();
|
|
} else {
|
|
this.form.disable();
|
|
}
|
|
});
|
|
|
|
this.route.data.pipe(take(1)).subscribe((data) => {
|
|
this.serviceType = data['serviceType'];
|
|
|
|
switch (this.serviceType) {
|
|
case PolicyComponentServiceType.MGMT:
|
|
this.service = this.injector.get(ManagementService as Type<ManagementService>);
|
|
|
|
const bread: Breadcrumb = {
|
|
type: BreadcrumbType.ORG,
|
|
routerLink: ['/org'],
|
|
};
|
|
|
|
this.breadcrumbService.setBreadcrumb([bread]);
|
|
break;
|
|
case PolicyComponentServiceType.ADMIN:
|
|
this.service = this.injector.get(AdminService as Type<AdminService>);
|
|
|
|
const iamBread = new Breadcrumb({
|
|
type: BreadcrumbType.ORG,
|
|
name: 'Instance',
|
|
routerLink: ['/instance'],
|
|
});
|
|
this.breadcrumbService.setBreadcrumb([iamBread]);
|
|
break;
|
|
}
|
|
|
|
this.id = this.route.snapshot.paramMap.get('id');
|
|
if (this.id) {
|
|
this.clientSecret?.setValidators([]);
|
|
this.getData(this.id);
|
|
}
|
|
});
|
|
}
|
|
|
|
private getData(id: string): void {
|
|
const req =
|
|
this.serviceType === PolicyComponentServiceType.ADMIN
|
|
? new AdminGetProviderByIDRequest()
|
|
: new MgmtGetProviderByIDRequest();
|
|
req.setId(id);
|
|
this.service
|
|
.getProviderByID(req)
|
|
.then((resp) => {
|
|
this.provider = resp.idp;
|
|
this.loading = false;
|
|
if (this.provider?.config?.google) {
|
|
this.form.patchValue(this.provider.config.google);
|
|
this.name?.setValue(this.provider.name);
|
|
}
|
|
})
|
|
.catch((error) => {
|
|
this.toast.showError(error);
|
|
this.loading = false;
|
|
});
|
|
}
|
|
|
|
public submitForm(): void {
|
|
this.provider ? this.updateGoogleProvider() : this.addGoogleProvider();
|
|
}
|
|
|
|
public addGoogleProvider(): void {
|
|
const req =
|
|
this.serviceType === PolicyComponentServiceType.MGMT
|
|
? new MgmtAddGoogleProviderRequest()
|
|
: new AdminAddGoogleProviderRequest();
|
|
|
|
req.setName(this.name?.value);
|
|
req.setClientId(this.clientId?.value);
|
|
req.setClientSecret(this.clientSecret?.value);
|
|
req.setScopesList(this.scopesList?.value);
|
|
req.setProviderOptions(this.options);
|
|
|
|
this.loading = true;
|
|
this.service
|
|
.addGoogleProvider(req)
|
|
.then((idp) => {
|
|
setTimeout(() => {
|
|
this.loading = false;
|
|
this.close();
|
|
}, 2000);
|
|
})
|
|
.catch((error) => {
|
|
this.toast.showError(error);
|
|
this.loading = false;
|
|
});
|
|
}
|
|
|
|
public updateGoogleProvider(): void {
|
|
if (this.provider) {
|
|
if (this.serviceType === PolicyComponentServiceType.MGMT) {
|
|
const req = new MgmtUpdateGoogleProviderRequest();
|
|
req.setId(this.provider.id);
|
|
req.setName(this.name?.value);
|
|
req.setClientId(this.clientId?.value);
|
|
req.setScopesList(this.scopesList?.value);
|
|
req.setProviderOptions(this.options);
|
|
|
|
if (this.updateClientSecret) {
|
|
req.setClientSecret(this.clientSecret?.value);
|
|
}
|
|
|
|
this.loading = true;
|
|
(this.service as ManagementService)
|
|
.updateGoogleProvider(req)
|
|
.then((idp) => {
|
|
setTimeout(() => {
|
|
this.loading = false;
|
|
this.close();
|
|
}, 2000);
|
|
})
|
|
.catch((error) => {
|
|
this.toast.showError(error);
|
|
this.loading = false;
|
|
});
|
|
} else if (PolicyComponentServiceType.ADMIN) {
|
|
const req = new AdminUpdateGoogleProviderRequest();
|
|
req.setId(this.provider.id);
|
|
req.setName(this.name?.value);
|
|
req.setClientId(this.clientId?.value);
|
|
req.setScopesList(this.scopesList?.value);
|
|
req.setProviderOptions(this.options);
|
|
|
|
if (this.updateClientSecret) {
|
|
req.setClientSecret(this.clientSecret?.value);
|
|
}
|
|
|
|
this.loading = true;
|
|
(this.service as AdminService)
|
|
.updateGoogleProvider(req)
|
|
.then((idp) => {
|
|
setTimeout(() => {
|
|
this.loading = false;
|
|
this.close();
|
|
}, 2000);
|
|
})
|
|
.catch((error) => {
|
|
this.loading = false;
|
|
this.toast.showError(error);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
public close(): void {
|
|
this._location.back();
|
|
}
|
|
|
|
public addScope(event: MatChipInputEvent): void {
|
|
const input = event.chipInput?.inputElement;
|
|
const value = event.value.trim();
|
|
|
|
if (value !== '') {
|
|
if (this.scopesList?.value) {
|
|
this.scopesList.value.push(value);
|
|
if (input) {
|
|
input.value = '';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public removeScope(uri: string): void {
|
|
if (this.scopesList?.value) {
|
|
const index = this.scopesList.value.indexOf(uri);
|
|
|
|
if (index !== undefined && index >= 0) {
|
|
this.scopesList.value.splice(index, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
public get name(): AbstractControl | null {
|
|
return this.form.get('name');
|
|
}
|
|
|
|
public get clientId(): AbstractControl | null {
|
|
return this.form.get('clientId');
|
|
}
|
|
|
|
public get clientSecret(): AbstractControl | null {
|
|
return this.form.get('clientSecret');
|
|
}
|
|
|
|
public get scopesList(): AbstractControl | null {
|
|
return this.form.get('scopesList');
|
|
}
|
|
}
|