[AC-2405] migrate SCIM component (#8781)
* migrating scim authentication component * migrating scim authentication component * migrating scim authentication component
This commit is contained in:
parent
588663f80f
commit
ca62f0cfa3
|
@ -1,39 +1,21 @@
|
||||||
<app-header></app-header>
|
<app-header></app-header>
|
||||||
|
|
||||||
<p>{{ "scimDescription" | i18n }}</p>
|
<p bitTypography="body1">{{ "scimDescription" | i18n }}</p>
|
||||||
|
|
||||||
<div *ngIf="loading">
|
<div *ngIf="loading">
|
||||||
<i
|
<i
|
||||||
class="bwi bwi-spinner bwi-spin text-muted"
|
class="bwi bwi-spinner bwi-spin tw-text-muted"
|
||||||
title="{{ 'loading' | i18n }}"
|
title="{{ 'loading' | i18n }}"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
></i>
|
></i>
|
||||||
<span class="sr-only">{{ "loading" | i18n }}</span>
|
<span class="tw-sr-only">{{ "loading" | i18n }}</span>
|
||||||
</div>
|
</div>
|
||||||
<form
|
<form [bitSubmit]="submit" [formGroup]="formData" *ngIf="!loading">
|
||||||
#form
|
<bit-form-control>
|
||||||
(ngSubmit)="submit()"
|
<input type="checkbox" bitCheckbox [formControl]="enabled" />
|
||||||
[appApiAction]="formPromise"
|
<bit-label>{{ "scimEnabledCheckboxDesc" | i18n }}</bit-label>
|
||||||
[formGroup]="formData"
|
<bit-hint>{{ "scimEnabledCheckboxDescHelpText" | i18n }}</bit-hint>
|
||||||
*ngIf="!loading"
|
</bit-form-control>
|
||||||
>
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="form-check">
|
|
||||||
<input
|
|
||||||
class="form-check-input"
|
|
||||||
type="checkbox"
|
|
||||||
id="enabled"
|
|
||||||
[formControl]="enabled"
|
|
||||||
name="Enabled"
|
|
||||||
aria-describedby="scimEnabledCheckboxDescHelpText"
|
|
||||||
/>
|
|
||||||
<label class="form-check-label" for="enabled">{{ "scimEnabledCheckboxDesc" | i18n }}</label>
|
|
||||||
<div id="scimEnabledCheckboxDescHelpText">
|
|
||||||
<small class="form-text text-muted">{{ "scimEnabledCheckboxDescHelpText" | i18n }}</small>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<bit-form-field *ngIf="showScimSettings">
|
<bit-form-field *ngIf="showScimSettings">
|
||||||
<bit-label>{{ "scimUrl" | i18n }}</bit-label>
|
<bit-label>{{ "scimUrl" | i18n }}</bit-label>
|
||||||
<input bitInput type="text" formControlName="endpointUrl" />
|
<input bitInput type="text" formControlName="endpointUrl" />
|
||||||
|
@ -41,7 +23,7 @@
|
||||||
type="button"
|
type="button"
|
||||||
bitSuffix
|
bitSuffix
|
||||||
bitIconButton="bwi-clone"
|
bitIconButton="bwi-clone"
|
||||||
(click)="copyScimUrl()"
|
[bitAction]="copyScimUrl"
|
||||||
[appA11yTitle]="'copyScimUrl' | i18n"
|
[appA11yTitle]="'copyScimUrl' | i18n"
|
||||||
></button>
|
></button>
|
||||||
</bit-form-field>
|
</bit-form-field>
|
||||||
|
@ -54,44 +36,32 @@
|
||||||
formControlName="clientSecret"
|
formControlName="clientSecret"
|
||||||
id="clientSecret"
|
id="clientSecret"
|
||||||
/>
|
/>
|
||||||
<ng-container>
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
bitSuffix
|
bitSuffix
|
||||||
[disabled]="$any(rotateButton).loading"
|
|
||||||
[bitIconButton]="showScimKey ? 'bwi-eye-slash' : 'bwi-eye'"
|
[bitIconButton]="showScimKey ? 'bwi-eye-slash' : 'bwi-eye'"
|
||||||
(click)="toggleScimKey()"
|
[bitAction]="toggleScimKey"
|
||||||
[appA11yTitle]="'toggleVisibility' | i18n"
|
[appA11yTitle]="'toggleVisibility' | i18n"
|
||||||
></button>
|
></button>
|
||||||
</ng-container>
|
|
||||||
<ng-container #rotateButton [appApiAction]="rotatePromise">
|
|
||||||
<!-- TODO: Convert to async actions -->
|
|
||||||
<button
|
<button
|
||||||
[loading]="$any(rotateButton).loading"
|
|
||||||
type="button"
|
type="button"
|
||||||
bitSuffix
|
bitSuffix
|
||||||
bitIconButton="bwi-generate"
|
bitIconButton="bwi-generate"
|
||||||
(click)="rotateScimKey()"
|
[bitAction]="rotateScimKey"
|
||||||
|
bitFormButton
|
||||||
[appA11yTitle]="'rotateScimKey' | i18n"
|
[appA11yTitle]="'rotateScimKey' | i18n"
|
||||||
></button>
|
></button>
|
||||||
</ng-container>
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
bitSuffix
|
bitSuffix
|
||||||
bitIconButton="bwi-clone"
|
bitIconButton="bwi-clone"
|
||||||
(click)="copyScimKey()"
|
[bitAction]="copyScimKey"
|
||||||
[appA11yTitle]="'copyScimKey' | i18n"
|
[appA11yTitle]="'copyScimKey' | i18n"
|
||||||
></button>
|
></button>
|
||||||
<bit-hint>{{ "scimApiKeyHelperText" | i18n }}</bit-hint>
|
<bit-hint>{{ "scimApiKeyHelperText" | i18n }}</bit-hint>
|
||||||
</bit-form-field>
|
</bit-form-field>
|
||||||
|
|
||||||
<button
|
<button type="submit" buttonType="primary" bitButton bitFormButton>
|
||||||
type="submit"
|
|
||||||
buttonType="primary"
|
|
||||||
bitButton
|
|
||||||
[loading]="form.loading"
|
|
||||||
[disabled]="form.loading"
|
|
||||||
>
|
|
||||||
{{ "save" | i18n }}
|
{{ "save" | i18n }}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -14,7 +14,6 @@ import { OrganizationApiKeyRequest } from "@bitwarden/common/admin-console/model
|
||||||
import { OrganizationConnectionRequest } from "@bitwarden/common/admin-console/models/request/organization-connection.request";
|
import { OrganizationConnectionRequest } from "@bitwarden/common/admin-console/models/request/organization-connection.request";
|
||||||
import { ScimConfigRequest } from "@bitwarden/common/admin-console/models/request/scim-config.request";
|
import { ScimConfigRequest } from "@bitwarden/common/admin-console/models/request/scim-config.request";
|
||||||
import { OrganizationConnectionResponse } from "@bitwarden/common/admin-console/models/response/organization-connection.response";
|
import { OrganizationConnectionResponse } from "@bitwarden/common/admin-console/models/response/organization-connection.response";
|
||||||
import { ApiKeyResponse } from "@bitwarden/common/auth/models/response/api-key.response";
|
|
||||||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
|
@ -29,8 +28,6 @@ export class ScimComponent implements OnInit {
|
||||||
loading = true;
|
loading = true;
|
||||||
organizationId: string;
|
organizationId: string;
|
||||||
existingConnectionId: string;
|
existingConnectionId: string;
|
||||||
formPromise: Promise<OrganizationConnectionResponse<ScimConfigApi>>;
|
|
||||||
rotatePromise: Promise<ApiKeyResponse>;
|
|
||||||
enabled = new FormControl(false);
|
enabled = new FormControl(false);
|
||||||
showScimSettings = false;
|
showScimSettings = false;
|
||||||
showScimKey = false;
|
showScimKey = false;
|
||||||
|
@ -82,11 +79,11 @@ export class ScimComponent implements OnInit {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async copyScimUrl() {
|
copyScimUrl = async () => {
|
||||||
this.platformUtilsService.copyToClipboard(await this.getScimEndpointUrl());
|
this.platformUtilsService.copyToClipboard(await this.getScimEndpointUrl());
|
||||||
}
|
};
|
||||||
|
|
||||||
async rotateScimKey() {
|
rotateScimKey = async () => {
|
||||||
const confirmed = await this.dialogService.openSimpleDialog({
|
const confirmed = await this.dialogService.openSimpleDialog({
|
||||||
title: { key: "rotateScimKey" },
|
title: { key: "rotateScimKey" },
|
||||||
content: { key: "rotateScimKeyWarning" },
|
content: { key: "rotateScimKeyWarning" },
|
||||||
|
@ -102,62 +99,50 @@ export class ScimComponent implements OnInit {
|
||||||
request.type = OrganizationApiKeyType.Scim;
|
request.type = OrganizationApiKeyType.Scim;
|
||||||
request.masterPasswordHash = "N/A";
|
request.masterPasswordHash = "N/A";
|
||||||
|
|
||||||
this.rotatePromise = this.organizationApiService.rotateApiKey(this.organizationId, request);
|
const response = await this.organizationApiService.rotateApiKey(this.organizationId, request);
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.rotatePromise;
|
|
||||||
this.formData.setValue({
|
this.formData.setValue({
|
||||||
endpointUrl: await this.getScimEndpointUrl(),
|
endpointUrl: await this.getScimEndpointUrl(),
|
||||||
clientSecret: response.apiKey,
|
clientSecret: response.apiKey,
|
||||||
});
|
});
|
||||||
this.platformUtilsService.showToast("success", null, this.i18nService.t("scimApiKeyRotated"));
|
this.platformUtilsService.showToast("success", null, this.i18nService.t("scimApiKeyRotated"));
|
||||||
} catch {
|
};
|
||||||
// Logged by appApiAction, do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
this.rotatePromise = null;
|
copyScimKey = async () => {
|
||||||
}
|
|
||||||
|
|
||||||
async copyScimKey() {
|
|
||||||
this.platformUtilsService.copyToClipboard(this.formData.get("clientSecret").value);
|
this.platformUtilsService.copyToClipboard(this.formData.get("clientSecret").value);
|
||||||
}
|
};
|
||||||
|
|
||||||
async submit() {
|
submit = async () => {
|
||||||
try {
|
|
||||||
const request = new OrganizationConnectionRequest(
|
const request = new OrganizationConnectionRequest(
|
||||||
this.organizationId,
|
this.organizationId,
|
||||||
OrganizationConnectionType.Scim,
|
OrganizationConnectionType.Scim,
|
||||||
true,
|
true,
|
||||||
new ScimConfigRequest(this.enabled.value),
|
new ScimConfigRequest(this.enabled.value),
|
||||||
);
|
);
|
||||||
|
let response: OrganizationConnectionResponse<ScimConfigApi>;
|
||||||
|
|
||||||
if (this.existingConnectionId == null) {
|
if (this.existingConnectionId == null) {
|
||||||
this.formPromise = this.apiService.createOrganizationConnection(request, ScimConfigApi);
|
response = await this.apiService.createOrganizationConnection(request, ScimConfigApi);
|
||||||
} else {
|
} else {
|
||||||
this.formPromise = this.apiService.updateOrganizationConnection(
|
response = await this.apiService.updateOrganizationConnection(
|
||||||
request,
|
request,
|
||||||
ScimConfigApi,
|
ScimConfigApi,
|
||||||
this.existingConnectionId,
|
this.existingConnectionId,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const response = (await this.formPromise) as OrganizationConnectionResponse<ScimConfigApi>;
|
|
||||||
await this.setConnectionFormValues(response);
|
await this.setConnectionFormValues(response);
|
||||||
this.platformUtilsService.showToast("success", null, this.i18nService.t("scimSettingsSaved"));
|
this.platformUtilsService.showToast("success", null, this.i18nService.t("scimSettingsSaved"));
|
||||||
} catch (e) {
|
};
|
||||||
// Logged by appApiAction, do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
this.formPromise = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getScimEndpointUrl() {
|
async getScimEndpointUrl() {
|
||||||
const env = await firstValueFrom(this.environmentService.environment$);
|
const env = await firstValueFrom(this.environmentService.environment$);
|
||||||
return env.getScimUrl() + "/" + this.organizationId;
|
return env.getScimUrl() + "/" + this.organizationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleScimKey() {
|
toggleScimKey = () => {
|
||||||
this.showScimKey = !this.showScimKey;
|
this.showScimKey = !this.showScimKey;
|
||||||
document.getElementById("clientSecret").focus();
|
document.getElementById("clientSecret").focus();
|
||||||
}
|
};
|
||||||
|
|
||||||
private async setConnectionFormValues(connection: OrganizationConnectionResponse<ScimConfigApi>) {
|
private async setConnectionFormValues(connection: OrganizationConnectionResponse<ScimConfigApi>) {
|
||||||
this.existingConnectionId = connection?.id;
|
this.existingConnectionId = connection?.id;
|
||||||
|
|
Loading…
Reference in New Issue