Added auth schemas + doc
MODIFY
src/assets/server/rest/v1/docs/e-mobility-oas.json
src/assets/server/rest/v1/docs/e-mobility-oas.json
"application/x-www-form-urlencoded": {
"schema": {
"type": "object",
+ "required": ["email", "tenant"],
"properties": {
"email": {
"type": "string",
- "example": "firstname.name@sap.com"
+ "example": "demo.demo@sap.com"
},
"captcha": {
"type": "string",
"example": "03AGdBq26Ca8rdqn0-odDV18kJCLnVytzGPXVPyW811IY4pqyQuak-o59MZlYfUIVS-ToLBiL4o7fBfPPvmkAhQLKoMXtqitKxRTG016wmGbFLvZWnOSkJKreB1Kx6n3dB7uYd302UVyVpJJ0BGFcmXWnWZmGnR3ZJC8IE1r7oVohcYVLttnKXtuhJwg5IdHe0HleYzOjxCBw9FnCJhVoSmaPn6FeVjWC9d8vSDwBq-18dA_cm6CQb7BhZm6LXWhMdW1_e_5DcSs1koj_vn3FGB7UQESsPp81WBfr6msCNiddNc1D4MRfF4wXeimJ1wplqoGOmMmI2Y_i-120grLrjkfzBNgDPQPWvfpUjeyW1f_T-5SaObYpUFEEZ4YW6Xt2revAWMmZ6i9_QOWWUcukaZU3jr_MzR1YIMscKrnBP3Zhl45zLXOY-0Bi28z6XxsMqqSHE8lY_C8B-7M-X3PNc_293qtrEnE2rhG9PU-RdFJG4dqBcwU6YfZJwwyXDWG7eyNG8iJoBDgCWrbib2jLKTmuwWCowApAoeA"
},
+ "hash": {
+ "type": "string"
+ },
"tenant": {
"type": "string",
- "example": ""
+ "example": "slf"
}
}
}
],
"responses": {
"200": {
- "description": "Password reset notification sent successfully"
+ "description": "Password reset notification sent successfully or password has been reset "
},
"500": {
"$ref": "#/components/responses/500BackendError"
},
"550": {
- "description": "User does not exist or is deleted logically"
+ "description": "Unknown tenant or user does not exist"
}
}
}
"name": "Email",
"required": true,
"schema": {
- "type": "string"
+ "type": "string",
+ "example": "demo.demo@sap.com"
}
},
{
"name": "Tenant",
"required": true,
"schema": {
- "type": "string"
+ "type": "string",
+ "example": "slf"
}
}
],
],
"responses": {
"200": {
- "description": "Successfully validated email"
+ "description": "Successfully resent email"
},
"500": {
"$ref": "#/components/responses/500BackendError"

ADD
src/assets/server/rest/v1/schemas/auth/auth-check-eula.json
+{
+ "title": "Check Eula",
+ "type": "object",
+ "properties": {
+ "Email": {
+ "$ref": "common.json#/definitions/email"
+ },
+ "Tenant": {
+ "$ref": "common.json#/definitions/subdomain"
+ }
+ },
+ "required": [
+ "Email",
+ "Tenant"
+ ]
+}

ADD
src/assets/server/rest/v1/schemas/auth/auth-eula.json
+{
+ "title": "Eula Request",
+ "type": "object",
+ "properties": {
+ "Language": {
+ "$ref": "common.json#/definitions/language"
+ },
+ "tenant": {
+ "$ref": "common.json#/definitions/subdomain"
+ }
+ }
+}

ADD
src/assets/server/rest/v1/schemas/auth/auth-resend-verification-email.json
+{
+ "title": "Resend verification Email",
+ "type": "object",
+ "properties": {
+ "email": {
+ "$ref": "common.json#/definitions/email"
+ },
+ "tenant": {
+ "$ref": "common.json#/definitions/subdomain"
+ },
+ "captcha": {
+ "$ref": "common.json#/definitions/captcha"
+ }
+ },
+ "required": [
+ "email",
+ "tenant",
+ "captcha"
+ ]
+}

ADD
src/assets/server/rest/v1/schemas/auth/auth-reset-password.json
+{
+ "title": "Reset password",
+ "type": "object",
+ "properties": {
+ "email": {
+ "$ref": "common.json#/definitions/email"
+ },
+ "tenant": {
+ "$ref": "common.json#/definitions/subdomain"
+ },
+ "captcha": {
+ "$ref": "common.json#/definitions/captcha"
+ },
+ "hash": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "passwords": {
+ "type": "object",
+ "properties": {
+ "password": {
+ "$ref": "common.json#/definitions/password"
+ },
+ "repeatPassword": {
+ "$ref": "common.json#/definitions/password"
+ }
+ }
+ }
+ },
+ "required": [
+ "email",
+ "captcha"
+ ],
+ "anyOf": [
+ { "required": ["captcha"] },
+ { "required": ["hash"] }
+ ]
+}

MODIFY
src/assets/server/rest/v1/schemas/auth/auth-signin.json
src/assets/server/rest/v1/schemas/auth/auth-signin.json
"required": [
"email",
"password",
- "acceptEula",
- "tenant"
+ "acceptEula"
]
}

MODIFY
src/assets/server/rest/v1/schemas/auth/auth-signon.json
src/assets/server/rest/v1/schemas/auth/auth-signon.json
{
- "title": "Sign in",
+ "title": "Sign On",
"type": "object",
"properties": {
"email": {
"firstName",
"passwords",
"acceptEula",
- "tenant",
"captcha"
]
}

ADD
src/assets/server/rest/v1/schemas/auth/auth-verify-email.json
+{
+ "title": "Verify email",
+ "type": "object",
+ "properties": {
+ "Email": {
+ "$ref": "common.json#/definitions/email"
+ },
+ "Tenant": {
+ "$ref": "common.json#/definitions/subdomain"
+ },
+ "VerificationToken": {
+ "type": "string",
+ "sanitize": "mongo"
+ }
+ },
+ "required": [
+ "Email",
+ "Tenant",
+ "VerificationToken"
+ ]
+}

MODIFY
src/assets/server/rest/v1/schemas/common/common.json
src/assets/server/rest/v1/schemas/common/common.json
},
"subdomain": {
"type": "string",
- "pattern": "^[a-z0-9]+$",
- "minLength": 1,
+ "pattern": "^[a-z0-9]*$",
"maxLength": 20,
"sanitize": "mongo"
},
"captcha": {
"type": "string",
"sanitize": "mongo"
+ },
+ "language": {
+ "type": "string",
+ "sanitize": "mongo"
}
}
}

MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
import { ExtractJwt, Strategy } from 'passport-jwt';
import { Handler, NextFunction, Request, RequestHandler, Response } from 'express';
-import { HttpLoginRequest, HttpResetPasswordRequest } from '../../../../types/requests/HttpUserRequest';
+import { HttpCheckEulaRequest, HttpLoginRequest, HttpRegisterUserRequest, HttpResetPasswordRequest } from '../../../../types/requests/HttpUserRequest';
import User, { UserRole, UserStatus } from '../../../../types/User';
import AppError from '../../../../exception/AppError';
-import AuthSecurity from './security/AuthSecurity';
import AuthValidator from '../validator/AuthValidation';
import Authorizations from '../../../../authorization/Authorizations';
import AxiosFactory from '../../../../utils/AxiosFactory';
@@ -61,22 +60,11 @@ export default class AuthService {
public static async handleLogIn(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = AuthValidator.getInstance().validateAuthSignIn(req.body);
- // Get Tenant
- const tenantID = await AuthService.getTenantID(filteredRequest.tenant);
- if (!tenantID) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.OBJECT_DOES_NOT_EXIST_ERROR,
- message: `User with Email '${filteredRequest.email}' tried to log in with an unknown tenant '${filteredRequest.tenant}'!`,
- module: MODULE_NAME,
- method: 'handleLogIn',
- action: action
- });
- }
- req.user = { tenantID };
- // Check
- if (!filteredRequest.email) {
+ let filteredRequest: Partial<HttpLoginRequest>;
+ try {
+ filteredRequest = AuthValidator.getInstance().validateAuthSignIn(req.body);
+ } catch (e) {
+ if (!req.body.email) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
@@ -85,7 +73,7 @@ export default class AuthService {
method: 'handleLogIn'
});
}
- if (!filteredRequest.password) {
+ if (!req.body.password) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
@@ -94,7 +82,7 @@ export default class AuthService {
method: 'handleLogIn'
});
}
- if (!filteredRequest.acceptEula) {
+ if (!req.body.acceptEula) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.USER_EULA_ERROR,
@@ -103,6 +91,20 @@ export default class AuthService {
method: 'handleLogIn'
});
}
+ }
+ // Get Tenant
+ const tenantID = await AuthService.getTenantID(filteredRequest.tenant);
+ if (!tenantID) {
+ throw new AppError({
+ source: Constants.CENTRAL_SERVER,
+ errorCode: HTTPError.OBJECT_DOES_NOT_EXIST_ERROR,
+ message: `User with Email '${filteredRequest.email}' tried to log in with an unknown tenant '${filteredRequest.tenant}'!`,
+ module: MODULE_NAME,
+ method: 'handleLogIn',
+ action: action
+ });
+ }
+ req.user = { tenantID };
const user = await UserStorage.getUserByEmail(tenantID, filteredRequest.email);
UtilsService.assertObjectExists(action, user, `User with email '${filteredRequest.email}' does not exist`,
MODULE_NAME, 'handleLogIn', req.user);
@@ -162,25 +164,12 @@ export default class AuthService {
public static async handleRegisterUser(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = AuthValidator.getInstance().validateAuthSignOn(req.body);
- filteredRequest.status = UserStatus.PENDING;
- if (!filteredRequest.locale) {
- filteredRequest.locale = Constants.DEFAULT_LOCALE;
- }
- // Get the Tenant
- const tenantID = await AuthService.getTenantID(filteredRequest.tenant);
- if (!tenantID) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.OBJECT_DOES_NOT_EXIST_ERROR,
- message: `User is trying to register with an unknown tenant '${filteredRequest.tenant}'!`,
- module: MODULE_NAME,
- method: 'handleGetEndUserLicenseAgreement'
- });
- }
- req.user = { tenantID };
+ let filteredRequest: Partial<HttpRegisterUserRequest>;
+ try {
+ filteredRequest = AuthValidator.getInstance().validateAuthSignOn(req.body);
+ } catch (e) {
// Check EULA
- if (!filteredRequest.acceptEula) {
+ if (!req.body.acceptEula) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.USER_EULA_ERROR,
@@ -190,7 +179,7 @@ export default class AuthService {
});
}
// Check
- if (!filteredRequest.captcha) {
+ if (!req.body.captcha) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
@@ -199,6 +188,23 @@ export default class AuthService {
method: 'handleRegisterUser'
});
}
+ }
+ filteredRequest.status = UserStatus.PENDING;
+ if (!filteredRequest.locale) {
+ filteredRequest.locale = Constants.DEFAULT_LOCALE;
+ }
+ // Get the Tenant
+ const tenantID = await AuthService.getTenantID(filteredRequest.tenant);
+ if (!tenantID) {
+ throw new AppError({
+ source: Constants.CENTRAL_SERVER,
+ errorCode: HTTPError.OBJECT_DOES_NOT_EXIST_ERROR,
+ message: `User is trying to register with an unknown tenant '${filteredRequest.tenant}'!`,
+ module: MODULE_NAME,
+ method: 'handleGetEndUserLicenseAgreement'
+ });
+ }
+ req.user = { tenantID };
// Check Captcha
const recaptchaURL = `https://www.google.com/recaptcha/api/siteverify?secret=${_centralSystemRestConfig.captchaSecretKey}&response=${filteredRequest.captcha}&remoteip=${req.connection.remoteAddress}`;
const response = await AxiosFactory.getAxiosInstance(tenantID).get(recaptchaURL);
@@ -447,7 +453,28 @@ export default class AuthService {
}
public static async handleUserPasswordReset(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
- const filteredRequest = AuthSecurity.filterResetPasswordRequest(req.body);
+ let filteredRequest: Partial<HttpResetPasswordRequest>;
+ try {
+ filteredRequest = AuthValidator.getInstance().validateAuthResetPassword(req.body);
+ } catch (e) {
+ if (!req.body.email) {
+ throw new AppError({
+ source: Constants.CENTRAL_SERVER,
+ errorCode: HTTPError.GENERAL_ERROR,
+ message: 'The E-mail is mandatory',
+ module: MODULE_NAME,
+ method: 'handleUserPasswordReset'
+ });
+ } else if (!req.body.captcha && !req.body.hash) {
+ throw new AppError({
+ source: Constants.CENTRAL_SERVER,
+ errorCode: HTTPError.GENERAL_ERROR,
+ message: 'The Captcha or the Hash is mandatory',
+ module: MODULE_NAME,
+ method: 'handleUserPasswordReset'
+ });
+ }
+ }
// Get Tenant
const tenantID = await AuthService.getTenantID(filteredRequest.tenant);
if (!tenantID) {
@@ -472,9 +499,12 @@ export default class AuthService {
public static async handleCheckEndUserLicenseAgreement(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = AuthSecurity.filterCheckEulaRequest(req.query);
+ let filteredRequest: Partial<HttpCheckEulaRequest>;
+ try {
+ filteredRequest = AuthValidator.getInstance().validateAuthCheckEula(req.query);
+ } catch (e) {
// Check
- if (!filteredRequest.Tenant) {
+ if (!req.body.Tenant) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
@@ -483,23 +513,23 @@ export default class AuthService {
method: 'handleCheckEndUserLicenseAgreement'
});
}
- // Get Tenant
- const tenantID = await AuthService.getTenantID(filteredRequest.Tenant);
- if (!tenantID) {
+ if (!req.body.Email) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
- message: 'The Tenant is mandatory',
+ message: 'The Email is mandatory',
module: MODULE_NAME,
method: 'handleCheckEndUserLicenseAgreement'
});
}
- // Check hash
- if (!filteredRequest.Email) {
+ }
+ // Get Tenant
+ const tenantID = await AuthService.getTenantID(filteredRequest.Tenant);
+ if (!tenantID) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
- message: 'The Email is mandatory',
+ message: 'The Tenant is mandatory',
module: MODULE_NAME,
method: 'handleCheckEndUserLicenseAgreement'
});
@@ -527,10 +557,9 @@ export default class AuthService {
public static async handleGetEndUserLicenseAgreement(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = AuthSecurity.filterEndUserLicenseAgreementRequest(req);
+ const filteredRequest = AuthValidator.getInstance().validateAuthEula({ ...req.query, ...req.headers });
// Get Tenant
const tenantID = await AuthService.getTenantID(filteredRequest.tenant);
-
if (!tenantID) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
@@ -548,46 +577,50 @@ export default class AuthService {
public static async handleVerifyEmail(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = AuthSecurity.filterVerifyEmailRequest(req.query);
- // Get Tenant
- const tenantID = await AuthService.getTenantID(filteredRequest.Tenant);
- if (!tenantID) {
+ let filteredRequest;
+ try {
+ filteredRequest = AuthValidator.getInstance().validateAuthVerifyEmail(req.body);
+ } catch (e) {
+ // Check email
+ if (!req.body.Email) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.OBJECT_DOES_NOT_EXIST_ERROR,
+ errorCode: HTTPError.GENERAL_ERROR,
action: action,
module: MODULE_NAME, method: 'handleVerifyEmail',
- message: `User is trying to access resource with an unknown tenant '${filteredRequest.Tenant}'!`
+ message: 'The email is mandatory'
});
}
- // Check that this is not the super tenant
- if (tenantID === Constants.DEFAULT_TENANT) {
+ // Check verificationToken
+ if (!req.body.VerificationToken) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
action: action,
module: MODULE_NAME, method: 'handleVerifyEmail',
- message: 'Cannot verify email in the Super Tenant'
+ message: 'Verification token is mandatory'
});
}
- // Check email
- if (!filteredRequest.Email) {
+ }
+ // Get Tenant
+ const tenantID = await AuthService.getTenantID(filteredRequest.Tenant);
+ if (!tenantID) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.GENERAL_ERROR,
+ errorCode: HTTPError.OBJECT_DOES_NOT_EXIST_ERROR,
action: action,
module: MODULE_NAME, method: 'handleVerifyEmail',
- message: 'The email is mandatory'
+ message: `User is trying to access resource with an unknown tenant '${filteredRequest.Tenant}'!`
});
}
- // Check verificationToken
- if (!filteredRequest.VerificationToken) {
+ // Check that this is not the super tenant
+ if (tenantID === Constants.DEFAULT_TENANT) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
action: action,
module: MODULE_NAME, method: 'handleVerifyEmail',
- message: 'Verification token is mandatory'
+ message: 'Cannot verify email in the Super Tenant'
});
}
// Check email
@@ -670,48 +703,51 @@ export default class AuthService {
public static async handleResendVerificationEmail(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = AuthSecurity.filterResendVerificationEmail(req.body);
- // Get the tenant
- const tenantID = await AuthService.getTenantID(filteredRequest.tenant);
-
- if (!tenantID) {
+ let filteredRequest;
+ try {
+ filteredRequest = AuthValidator.getInstance().validateAuthResendVerificationEmail(req.body);
+ } catch (e) {
+ // Check email
+ if (!filteredRequest.email) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.OBJECT_DOES_NOT_EXIST_ERROR,
- message: `User is trying to access resource with an unknown tenant '${filteredRequest.tenant}'!`,
+ errorCode: HTTPError.GENERAL_ERROR,
+ message: 'The Email is mandatory',
module: MODULE_NAME,
method: 'handleResendVerificationEmail',
action: action
});
}
- // Check that this is not the super tenant
- if (tenantID === Constants.DEFAULT_TENANT) {
+ // Check captcha
+ if (!filteredRequest.captcha) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
- message: 'Cannot request a verification Email in the Super Tenant',
+ message: 'The captcha is mandatory',
module: MODULE_NAME,
method: 'handleResendVerificationEmail',
action: action
});
}
- // Check email
- if (!filteredRequest.email) {
+ }
+ // Get the tenant
+ const tenantID = await AuthService.getTenantID(filteredRequest.tenant);
+ if (!tenantID) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.GENERAL_ERROR,
- message: 'The Email is mandatory',
+ errorCode: HTTPError.OBJECT_DOES_NOT_EXIST_ERROR,
+ message: `User is trying to access resource with an unknown tenant '${filteredRequest.tenant}'!`,
module: MODULE_NAME,
method: 'handleResendVerificationEmail',
action: action
});
}
- // Check captcha
- if (!filteredRequest.captcha) {
+ // Check that this is not the super tenant
+ if (tenantID === Constants.DEFAULT_TENANT) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.GENERAL_ERROR,
- message: 'The captcha is mandatory',
+ message: 'Cannot request a verification Email in the Super Tenant',
module: MODULE_NAME,
method: 'handleResendVerificationEmail',
action: action

DELETE
src/server/rest/v1/service/security/AuthSecurity.ts
-import { HttpCheckEulaRequest, HttpLoginRequest, HttpRegisterUserRequest, HttpResendVerificationMailRequest, HttpResetPasswordRequest, HttpVerifyEmailRequest } from '../../../../../types/requests/HttpUserRequest';
-
-import Constants from '../../../../../utils/Constants';
-import { Request } from 'express';
-import { UserStatus } from '../../../../../types/User';
-import UtilsSecurity from './UtilsSecurity';
-import sanitize from 'mongo-sanitize';
-
-export default class AuthSecurity {
-
- public static filterCheckEulaRequest(request: any): HttpCheckEulaRequest {
- return {
- Email: sanitize(request.Email),
- Tenant: sanitize(request.Tenant)
- };
- }
-
- public static filterResetPasswordRequest(request: HttpResetPasswordRequest): Partial<HttpResetPasswordRequest> {
- const filteredRequest = {} as HttpResetPasswordRequest;
- // Set
- filteredRequest.email = sanitize(request.email);
- if (request.passwords) {
- filteredRequest.password = sanitize(request.passwords.password);
- filteredRequest.repeatPassword = sanitize(request.passwords.repeatPassword);
- }
- filteredRequest.tenant = sanitize(request.tenant);
- filteredRequest.captcha = sanitize(request.captcha);
- filteredRequest.hash = sanitize(request.hash);
- return filteredRequest;
- }
-
- public static filterRegisterUserRequest(request: HttpRegisterUserRequest): Partial<HttpRegisterUserRequest> {
- return {
- name: sanitize(request.name),
- firstName: sanitize(request.firstName),
- password: sanitize(
- typeof request.passwords === 'string' ? JSON.parse(request.passwords).password : request.passwords.password
- ),
- acceptEula: sanitize(request.acceptEula),
- captcha: sanitize(request.captcha),
- status: UserStatus.PENDING,
- email: sanitize(request.email),
- locale: request.locale ? sanitize(request.locale.substring(0, 5)) : Constants.DEFAULT_LOCALE,
- tenant: sanitize(request.tenant)
- };
- }
-
- public static filterVerifyEmailRequest(request: any): Partial<HttpVerifyEmailRequest> {
- return {
- Email: sanitize(request.Email),
- Tenant: sanitize(request.Tenant),
- VerificationToken: sanitize(request.VerificationToken)
- };
- }
-
- public static filterResendVerificationEmail(request: HttpResendVerificationMailRequest): Partial<HttpResendVerificationMailRequest> {
- return {
- email: sanitize(request.email),
- tenant: sanitize(request.tenant),
- captcha: sanitize(request.captcha)
- };
- }
-
- public static filterEndUserLicenseAgreementRequest(request: Request): {Language: string; tenant: string} {
- const filteredRequest: any = {};
- // Set
- if (request.query) {
- filteredRequest.Language = sanitize(request.query.Language);
- }
- if (request.headers) {
- filteredRequest.tenant = sanitize(request.headers.tenant);
- }
- return filteredRequest as {Language: string; tenant: string};
- }
-}

MODIFY
src/server/rest/v1/validator/AuthValidation.ts
src/server/rest/v1/validator/AuthValidation.ts
-import { HttpLoginRequest, HttpRegisterUserRequest } from '../../../../types/requests/HttpUserRequest';
+import { HttpCheckEulaRequest, HttpEulaRequest, HttpLoginRequest, HttpRegisterUserRequest, HttpResendVerificationMailRequest, HttpResetPasswordRequest, HttpVerifyEmailRequest } from '../../../../types/requests/HttpUserRequest';
import SchemaValidator from './SchemaValidator';
import fs from 'fs';
@@ -8,11 +8,21 @@ export default class AuthValidator extends SchemaValidator {
private static _instance: AuthValidator | undefined;
private _authSignIn: any;
private _authSignOn: any;
+ private _authResetPassword: any;
+ private _authCheckEula: any;
+ private _authVerifyEmail: any;
+ private _authResendVerificationEmail: any;
+ private _authEula: any;
private constructor() {
super('AuthValidator');
this._authSignIn = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/auth/auth-signin.json`, 'utf8'));
this._authSignOn = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/auth/auth-signon.json`, 'utf8'));
+ this._authResetPassword = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/auth/auth-reset-password.json`, 'utf8'));
+ this._authCheckEula = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/auth/auth-check-eula.json`, 'utf8'));
+ this._authVerifyEmail = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/auth/auth-verify-email.json`, 'utf8'));
+ this._authResendVerificationEmail = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/auth/auth-resend-verification-email.json`, 'utf8'));
+ this._authEula = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/auth/auth-eula.json`, 'utf8'));
}
public static getInstance(): AuthValidator {
@@ -22,15 +32,45 @@ export default class AuthValidator extends SchemaValidator {
return AuthValidator._instance;
}
- public validateAuthSignIn(auth: HttpLoginRequest): HttpLoginRequest {
+ public validateAuthSignIn(data: HttpLoginRequest): HttpLoginRequest {
// Validate schema
- this.validate(this._authSignIn, auth);
- return auth;
+ this.validate(this._authSignIn, data);
+ return data;
}
- public validateAuthSignOn(auth: HttpRegisterUserRequest): Partial<HttpRegisterUserRequest> {
+ public validateAuthSignOn(data: HttpRegisterUserRequest): Partial<HttpRegisterUserRequest> {
// Validate schema
- this.validate(this._authSignOn, auth);
- return auth;
+ this.validate(this._authSignOn, data);
+ return data;
+ }
+
+ public validateAuthResetPassword(data: HttpResetPasswordRequest): Partial<HttpResetPasswordRequest> {
+ // Validate schema
+ this.validate(this._authResetPassword, data);
+ return data;
+ }
+
+ public validateAuthCheckEula(data: any): Partial<HttpCheckEulaRequest> {
+ // Validate schema
+ this.validate(this._authCheckEula, data);
+ return data;
+ }
+
+ public validateAuthVerifyEmail(data: any): Partial<HttpVerifyEmailRequest> {
+ // Validate schema
+ this.validate(this._authVerifyEmail, data);
+ return data;
+ }
+
+ public validateAuthResendVerificationEmail(data: any): Partial<HttpResendVerificationMailRequest> {
+ // Validate schema
+ this.validate(this._authResendVerificationEmail, data);
+ return data;
+ }
+
+ public validateAuthEula(data: any): Partial<HttpEulaRequest> {
+ // Validate schema
+ this.validate(this._authEula, data);
+ return data;
}
}

MODIFY
src/types/requests/HttpUserRequest.ts
src/types/requests/HttpUserRequest.ts
@@ -96,3 +96,8 @@ export interface HttpResendVerificationMailRequest {
tenant: string;
captcha: string;
}
+
+export interface HttpEulaRequest {
+ Language: string;
+ tenant: string;
+}

MODIFY
test/api/client/AuthenticationApi.ts
test/api/client/AuthenticationApi.ts
@@ -91,7 +91,7 @@ export default class AuthenticationApi {
public async verifyEmail(email, verificationToken, tenant = '') {
const data = {
Email: email,
- tenant: tenant,
+ Tenant: tenant,
VerificationToken: verificationToken
};
// Send

Added auth schemas + doc