Commit 2a79fe45 authored by Revant Nandgaonkar's avatar Revant Nandgaonkar

Refactor and fixes

Merge branch 'refactor-and-fixes' into 'develop'

See merge request castlecraft/building-blocks!296
parents 85ca1df9 a39e2c03
......@@ -69,6 +69,8 @@ export class OAuth2Service {
name: user.name,
email: user.email,
roles: user.roles,
verified_email: user.email,
verified: user.email ? true : false,
});
}),
);
......
......@@ -213,8 +213,13 @@ export class OAuth2orizeSetup implements OnModuleInit, OnApplicationBootstrap {
async (client, user, done) => {
// Check if grant request qualifies for immediate approval
if (!user) return done(null, false);
// Auto-approve
if (client.isTrusted) return done(null, true);
if (client.isTrusted) {
return done(null, true);
} else if (client.autoApprove) {
return done(null, true);
}
try {
// findByUserIdAndClientId
......
......@@ -10,6 +10,7 @@ export interface Client extends Document {
clientId?: string;
clientSecret?: string;
isTrusted?: number;
autoApprove?: boolean;
redirectUris?: string[];
allowedScopes?: string[];
userDeleteEndpoint?: string;
......
......@@ -13,6 +13,7 @@ const schema = new mongoose.Schema(
clientId: { type: String, default: uuidv4 },
clientSecret: { type: String, default: randomBytes32 },
isTrusted: Number,
autoApprove: Boolean,
redirectUris: [String],
allowedScopes: [String],
userDeleteEndpoint: String,
......
......@@ -4,6 +4,7 @@ import {
IsString,
IsNumberString,
ValidateNested,
IsBoolean,
} from 'class-validator';
import { ApiModelProperty } from '@nestjs/swagger';
import { i18n } from '../../../i18n/i18n.config';
......@@ -23,11 +24,21 @@ export class CreateClientDto {
@IsNumberString()
@IsOptional()
@ApiModelProperty({
description: i18n.__('Skips the Allow/Deny screen if value is 1'),
description: i18n.__(
'Treat this as internal trusted client if trust is greater than 0',
),
type: 'number',
})
isTrusted: number;
@IsBoolean()
@IsOptional()
@ApiModelProperty({
description: i18n.__('Skips the Allow/Deny screen if value is true'),
type: 'boolean',
})
autoApprove: boolean;
@ApiModelProperty({
description: i18n.__(
'Client app endpoint which will receive the token/code',
......
......@@ -74,5 +74,7 @@
"Password less login is already disabled": "Password less login is already disabled",
"Password less login is already enabled": "Password less login is already enabled",
"Bearer Token Revoked Successfully": "Bearer Token Revoked Successfully",
"Invalid Bearer Token": "Invalid Bearer Token"
"Invalid Bearer Token": "Invalid Bearer Token",
"Treat this as internal trusted client if trust is greater than 0": "Treat this as internal trusted client if trust is greater than 0",
"Skips the Allow/Deny screen if value is true": "Skips the Allow/Deny screen if value is true"
}
\ No newline at end of file
import { Column, Entity, BaseEntity, ObjectID, ObjectIdColumn } from 'typeorm';
import * as uuidv4 from 'uuid/v4';
@Entity()
export const OAUTH2_PROVIDER = 'oauth2_provider';
@Entity(OAUTH2_PROVIDER)
export class OAuth2Provider extends BaseEntity {
@ObjectIdColumn()
_id: ObjectID;
......
.client-checkboxes {
padding-right: 2px;
}
\ No newline at end of file
......@@ -3,9 +3,10 @@
<mat-card>
<mat-card-title>{{ clientName || "New Client" }}</mat-card-title>
<mat-card-content fxLayout="column">
<mat-form-field>
<mat-form-field fxLayout="column" fxLayoutGap="1em">
<input matInput placeholder="Client Name" formControlName="clientName" required>
<mat-checkbox formControlName="isTrusted" matSuffix>Trusted</mat-checkbox>
<mat-checkbox formControlName="isTrusted" matSuffix class="client-checkboxes">Trusted</mat-checkbox>
<mat-checkbox formControlName="autoApprove" matSuffix>Auto Approve</mat-checkbox>
</mat-form-field>
<mat-form-field *ngIf="clientId">
<input matInput placeholder="Client ID" formControlName="clientId" password readonly>
......
......@@ -25,6 +25,7 @@ export class ClientComponent implements OnInit {
clientSecret: string;
clientURL: string;
isTrusted: boolean;
autoApprove: boolean;
clientScopes: any[];
callbackURLs: string[];
tokenDeleteEndpoint: string;
......@@ -58,6 +59,7 @@ export class ClientComponent implements OnInit {
userDeleteEndpoint: this.userDeleteEndpoint,
callbackURLForms: this.formBuilder.array([]),
isTrusted: this.isTrusted,
autoApprove: this.autoApprove,
clientId: this.clientId,
clientSecret: this.clientSecret,
changedClientSecret: this.changedClientSecret,
......@@ -104,6 +106,7 @@ export class ClientComponent implements OnInit {
this.getCallbackURLs(),
this.clientForm.controls.clientScopes.value,
this.clientForm.controls.isTrusted.value ? '1' : '0',
this.clientForm.controls.autoApprove.value,
)
.subscribe({
next: success => {
......@@ -136,6 +139,7 @@ export class ClientComponent implements OnInit {
this.getCallbackURLs(),
this.clientForm.controls.clientScopes.value,
this.clientForm.controls.isTrusted.value,
this.clientForm.controls.autoApprove.value,
)
.subscribe({
next: success => {
......@@ -164,6 +168,7 @@ export class ClientComponent implements OnInit {
this.clientSecret = client.clientSecret;
this.clientName = client.name;
this.callbackURLs = client.redirectUris;
this.isTrusted = client.isTrusted;
this.clientForm.controls.tokenDeleteEndpoint.setValue(
client.tokenDeleteEndpoint,
);
......@@ -180,6 +185,25 @@ export class ClientComponent implements OnInit {
this.clientForm.controls.clientSecret.setValue(client.clientSecret);
this.clientForm.controls.clientName.setValue(client.name);
this.clientForm.controls.isTrusted.setValue(client.isTrusted);
this.clientForm.controls.autoApprove.setValue(client.autoApprove);
this.clientForm.controls.clientScopes.setValue(client.allowedScopes);
this.toggleTrustedAutoApprove(this.isTrusted);
this.clientForm.controls.isTrusted.valueChanges.subscribe({
next: value => {
this.toggleTrustedAutoApprove(value);
},
error: error => {},
});
}
toggleTrustedAutoApprove(isTrusted: boolean) {
if (isTrusted) {
this.clientForm.controls.autoApprove.setValue(true);
this.clientForm.controls.autoApprove.disable();
} else {
this.clientForm.controls.autoApprove.setValue(false);
this.clientForm.controls.autoApprove.enable();
}
}
}
......@@ -45,6 +45,7 @@ export class ClientService {
callbackURLs: string[],
scopes: string[],
isTrusted: string,
autoApprove: boolean,
) {
const url = `${this.storageService.getInfo(ISSUER_URL)}/client/v1/create`;
const clientData = {
......@@ -52,6 +53,7 @@ export class ClientService {
redirectUris: callbackURLs,
allowedScopes: scopes,
isTrusted,
autoApprove,
};
return this.http.post(url, clientData);
}
......@@ -64,6 +66,7 @@ export class ClientService {
callbackURLs: string[],
scopes: string[],
isTrusted: boolean,
autoApprove: boolean,
) {
const url = `${this.storageService.getInfo(
ISSUER_URL,
......@@ -75,6 +78,7 @@ export class ClientService {
redirectUris: callbackURLs,
allowedScopes: scopes,
isTrusted,
autoApprove,
});
}
......
......@@ -45,7 +45,7 @@
<mat-nav-list>
<a mat-list-item routerLink="/email/list">Email</a>
<a mat-list-item routerLink="/storage/list">Storage</a>
<a mat-list-item routerLink="/oauth2_provider/list">OAuth2 Provider</a>
<!-- <a mat-list-item routerLink="/oauth2_provider/list">OAuth2 Provider</a> -->
<a mat-list-item routerLink="/communication_settings">Settings</a>
</mat-nav-list>
</mat-expansion-panel>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment