Skip to content

Commit

Permalink
UI: Change validation application secret for OAuth2
Browse files Browse the repository at this point in the history
  • Loading branch information
vvlladd28 committed May 28, 2024
1 parent 7fbbaa2 commit 7cb87e8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<div [formGroupName]="n" fxLayout="row" fxLayoutGap="8px">
<div fxFlex fxLayout="row" fxLayout.xs="column" fxLayoutGap="8px">
<div fxFlex fxLayout="column">
<mat-form-field fxFlex class="mat-block" floatLabel="always">
<mat-form-field fxFlex class="mat-block" floatLabel="always" subscriptSizing="dynamic">
<mat-label translate>admin.oauth2.mobile-package</mat-label>
<input matInput formControlName="pkgName" placeholder="{{ 'admin.oauth2.mobile-package-placeholder' | translate }}" required>
<mat-hint translate>admin.oauth2.mobile-package-hint</mat-hint>
Expand All @@ -166,9 +166,9 @@
</mat-error>
</div>
<div fxFlex fxLayout="row">
<mat-form-field fxFlex class="mat-block">
<mat-form-field fxFlex class="mat-block" subscriptSizing="dynamic">
<mat-label translate>admin.oauth2.mobile-app-secret</mat-label>
<textarea matInput formControlName="appSecret" rows="1" required></textarea>
<input matInput formControlName="appSecret" required>
<tb-copy-button
matSuffix
miniButton="false"
Expand All @@ -178,8 +178,15 @@
tooltipPosition="above"
icon="mdi:clipboard-arrow-left">
</tb-copy-button>
<mat-error *ngIf="mobileInfo.get('appSecret').invalid">
{{ 'admin.oauth2.invalid-mobile-app-secret' | translate }}
<mat-hint translate>admin.oauth2.mobile-app-secret-hint</mat-hint>
<mat-error *ngIf="mobileInfo.get('appSecret').hasError('required')">
{{ 'admin.oauth2.mobile-app-secret-required' | translate }}
</mat-error>
<mat-error *ngIf="mobileInfo.get('appSecret').hasError('base64')">
{{ 'admin.oauth2.mobile-app-secret-min-length' | translate }}
</mat-error>
<mat-error *ngIf="mobileInfo.get('appSecret').hasError('minLength')">
{{ 'admin.oauth2.mobile-app-secret-base64' | translate }}
</mat-error>
</mat-form-field>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
import {
AbstractControl,
FormControl,
UntypedFormArray,
UntypedFormBuilder,
UntypedFormGroup,
Expand Down Expand Up @@ -215,7 +216,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha
this.oauth2SettingsForm.get('edgeEnabled').patchValue(false);
this.oauth2SettingsForm.get('edgeEnabled').disable();
}
}))
}));
}

private initOAuth2Settings(oauth2Info: OAuth2Info): void {
Expand Down Expand Up @@ -302,11 +303,25 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha
private buildMobileInfoForm(mobileInfo?: OAuth2MobileInfo): UntypedFormGroup {
return this.fb.group({
pkgName: [mobileInfo?.pkgName, [Validators.required]],
appSecret: [mobileInfo?.appSecret, [Validators.required, Validators.minLength(16), Validators.maxLength(2048),
Validators.pattern(/^[A-Za-z0-9]+$/)]],
appSecret: [mobileInfo?.appSecret, [Validators.required, this.base64Format]],
}, {validators: this.uniquePkgNameValidator});
}

private base64Format(control: FormControl): { [key: string]: boolean } | null {
if (control.value === '') {
return null;
}
try {
const value = atob(control.value);
if (value.length < 64) {
return {minLength: true};
}
return null;
} catch (e) {
return {base64: true};
}
}

private buildRegistrationForm(registration?: OAuth2RegistrationInfo): UntypedFormGroup {
let additionalInfo = null;
if (isDefinedAndNotNull(registration?.additionalInfo)) {
Expand Down Expand Up @@ -556,7 +571,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha
addMobileInfo(control: AbstractControl): void {
this.mobileInfos(control).push(this.buildMobileInfoForm({
pkgName: '',
appSecret: randomAlphanumeric(24)
appSecret: btoa(randomAlphanumeric(64))
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class SecuritySettingsComponent extends PageComponent implements HasConfi
}
try {
const value = atob(control.value);
if (value.length < 32) {
if (value.length < 64) {
return {minLength: true};
}
return null;
Expand Down
4 changes: 4 additions & 0 deletions ui-ngx/src/assets/locale/locale.constant-en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@
"mobile-package-hint": "For Android: your own unique Application ID. For iOS: Product bundle identifier.",
"mobile-package-unique": "Application package must be unique.",
"mobile-app-secret": "Application secret",
"mobile-app-secret-hint": "Base64 encoded string representing at least 512 bits of data.",
"mobile-app-secret-required": "Application secret is required.",
"mobile-app-secret-min-length": "Application secret must be at least 512 bits of data.",
"mobile-app-secret-base64": "Application secret must be base64 format.",
"invalid-mobile-app-secret": "Application secret must contain only alphanumeric characters and must be between 16 and 2048 characters long.",
"copy-mobile-app-secret": "Copy application secret",
"add-mobile-app": "Add application",
Expand Down

0 comments on commit 7cb87e8

Please sign in to comment.