mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-17 23:59:09 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b168612a4 |
@@ -94,8 +94,6 @@ spec:
|
|||||||
value: {{ .Values.maestro.open_group_id }}
|
value: {{ .Values.maestro.open_group_id }}
|
||||||
- name: DEDICATED_PROXY
|
- name: DEDICATED_PROXY
|
||||||
value: {{ .Values.maestro.dedicated_proxy }}
|
value: {{ .Values.maestro.dedicated_proxy }}
|
||||||
- name: COOKIE_SECRET
|
|
||||||
value: {{ .Values.maestro.cookie_secret }}
|
|
||||||
- name: REDIS_DATABASE
|
- name: REDIS_DATABASE
|
||||||
value: "{{ .Values.maestro.redis_database }}"
|
value: "{{ .Values.maestro.redis_database }}"
|
||||||
- name: REDIS_HOST
|
- name: REDIS_HOST
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ metadata:
|
|||||||
nginx.ingress.kubernetes.io/server-snippet: |
|
nginx.ingress.kubernetes.io/server-snippet: |
|
||||||
underscores_in_headers on;
|
underscores_in_headers on;
|
||||||
ignore_invalid_headers on;
|
ignore_invalid_headers on;
|
||||||
nginx.ingress.kubernetes.io/proxy-buffer-size: "16k"
|
|
||||||
nginx.ingress.kubernetes.io/proxy-buffers-number: "8"
|
|
||||||
nginx.ingress.kubernetes.io/proxy-busy-buffers-size: "64k"
|
|
||||||
{{- if .Values.maestro.restricted_ip}}
|
{{- if .Values.maestro.restricted_ip}}
|
||||||
nginx.ingress.kubernetes.io/whitelist-source-range: {{ .Values.maestro.restricted_ip }}
|
nginx.ingress.kubernetes.io/whitelist-source-range: {{ .Values.maestro.restricted_ip }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ maestro:
|
|||||||
tr_factory_url: in-factory.stg.dadosfera.ai
|
tr_factory_url: in-factory.stg.dadosfera.ai
|
||||||
open_customer_id: b3e3dfe5-b992-4586-a73c-c0b0c00f615d
|
open_customer_id: b3e3dfe5-b992-4586-a73c-c0b0c00f615d
|
||||||
open_group_id: e3f98a2f-7748-4981-8505-7695c8ca8218
|
open_group_id: e3f98a2f-7748-4981-8505-7695c8ca8218
|
||||||
cookie_secret: "ff7bc13823edb2ae50d248e5780bddc9d4b31c36"
|
|
||||||
|
|
||||||
hostname: maestro.stg.dadosfera.ai
|
hostname: maestro.stg.dadosfera.ai
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ maestro:
|
|||||||
redis_host: "product-redis-prd.z4xvqj.0001.use1.cache.amazonaws.com"
|
redis_host: "product-redis-prd.z4xvqj.0001.use1.cache.amazonaws.com"
|
||||||
redis_port: "6379"
|
redis_port: "6379"
|
||||||
redis_database: "0"
|
redis_database: "0"
|
||||||
cookie_secret: "13cc5e136d3074bcc05bec8697092ec1f5f376bf"
|
|
||||||
autoscaling:
|
autoscaling:
|
||||||
enabled: false
|
enabled: false
|
||||||
minReplicas: 1
|
minReplicas: 1
|
||||||
|
|||||||
+183
-28
@@ -34,7 +34,14 @@
|
|||||||
},
|
},
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": ""
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/AuthSignInRes"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tags": [
|
"tags": [
|
||||||
@@ -668,33 +675,6 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/auth/me": {
|
|
||||||
"get": {
|
|
||||||
"operationId": "AuthController_getMe",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "dadosfera-lang",
|
|
||||||
"in": "header",
|
|
||||||
"required": false,
|
|
||||||
"schema": {
|
|
||||||
"enum": [
|
|
||||||
"pt-br",
|
|
||||||
"en-us"
|
|
||||||
],
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"tags": [
|
|
||||||
"Auth"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/connections": {
|
"/connections": {
|
||||||
"post": {
|
"post": {
|
||||||
"operationId": "ConnectionController_createConnection",
|
"operationId": "ConnectionController_createConnection",
|
||||||
@@ -6811,6 +6791,181 @@
|
|||||||
"password"
|
"password"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"AuthCustomer": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"modules": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"displayName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"tier": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"scheduleLimit": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"links": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"themeEnabled": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"enforceMfa": {
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"modules",
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"displayName",
|
||||||
|
"tier",
|
||||||
|
"scheduleLimit",
|
||||||
|
"links",
|
||||||
|
"themeEnabled",
|
||||||
|
"enforceMfa"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"AuthUser": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"username": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"createdAt": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"username",
|
||||||
|
"createdAt"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"AuthTokens": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"accessToken": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"refreshToken": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"termsOfUseToken": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"idToken": {
|
||||||
|
"type": "string",
|
||||||
|
"deprecated": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"accessToken",
|
||||||
|
"refreshToken",
|
||||||
|
"idToken"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"TermsOfUse": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"version": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"publicUrl": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"enforceDate": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"createdAt": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"version",
|
||||||
|
"publicUrl",
|
||||||
|
"enforceDate",
|
||||||
|
"createdAt"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"TermsOfUseStatus": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"status": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"pending",
|
||||||
|
"required",
|
||||||
|
"ok"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"lastSigned": {
|
||||||
|
"$ref": "#/components/schemas/TermsOfUse"
|
||||||
|
},
|
||||||
|
"next": {
|
||||||
|
"$ref": "#/components/schemas/TermsOfUse"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"status"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"AuthSignInRes": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"permissions": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mfaStatus": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"pending",
|
||||||
|
"none",
|
||||||
|
"totp"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"customer": {
|
||||||
|
"$ref": "#/components/schemas/AuthCustomer"
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"$ref": "#/components/schemas/AuthUser"
|
||||||
|
},
|
||||||
|
"tokens": {
|
||||||
|
"$ref": "#/components/schemas/AuthTokens"
|
||||||
|
},
|
||||||
|
"termsOfUse": {
|
||||||
|
"$ref": "#/components/schemas/TermsOfUseStatus"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"permissions",
|
||||||
|
"mfaStatus"
|
||||||
|
]
|
||||||
|
},
|
||||||
"AuthRefreshAccessTokenReq": {
|
"AuthRefreshAccessTokenReq": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
Vendored
-1
@@ -15,7 +15,6 @@ declare global {
|
|||||||
OPEN_GROUP_ID: string;
|
OPEN_GROUP_ID: string;
|
||||||
OPEN_CUSTOMER_ID: string;
|
OPEN_CUSTOMER_ID: string;
|
||||||
DEDICATED_PROXY: string;
|
DEDICATED_PROXY: string;
|
||||||
COOKIE_SECRET: string;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
-34
@@ -31,7 +31,6 @@
|
|||||||
"cache-manager-ioredis-yet": "^1.1.0",
|
"cache-manager-ioredis-yet": "^1.1.0",
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"class-validator": "^0.14.0",
|
"class-validator": "^0.14.0",
|
||||||
"cookie-parser": "^1.4.7",
|
|
||||||
"cron-parser": "^4.9.0",
|
"cron-parser": "^4.9.0",
|
||||||
"csv": "^6.3.11",
|
"csv": "^6.3.11",
|
||||||
"dotenv": "^14.3.2",
|
"dotenv": "^14.3.2",
|
||||||
@@ -57,7 +56,6 @@
|
|||||||
"swagger-ui-express": "^4.6.3"
|
"swagger-ui-express": "^4.6.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/cookie-parser": "^1.4.9",
|
|
||||||
"@types/cache-manager": "^4.0.6",
|
"@types/cache-manager": "^4.0.6",
|
||||||
"@types/express": "^4.17.17",
|
"@types/express": "^4.17.17",
|
||||||
"@types/express-session": "^1.18.1",
|
"@types/express-session": "^1.18.1",
|
||||||
@@ -3744,16 +3742,6 @@
|
|||||||
"@types/node": "*"
|
"@types/node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/cookie-parser": {
|
|
||||||
"version": "1.4.9",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/cookie-parser/-/cookie-parser-1.4.9.tgz",
|
|
||||||
"integrity": "sha512-tGZiZ2Gtc4m3wIdLkZ8mkj1T6CEHb35+VApbL2T14Dew8HA7c+04dmKqsKRNC+8RJPm16JEK0tFSwdZqubfc4g==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"peerDependencies": {
|
|
||||||
"@types/express": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@types/cookiejar": {
|
"node_modules/@types/cookiejar": {
|
||||||
"version": "2.1.5",
|
"version": "2.1.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.5.tgz",
|
||||||
@@ -5884,28 +5872,6 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/cookie-parser": {
|
|
||||||
"version": "1.4.7",
|
|
||||||
"resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.7.tgz",
|
|
||||||
"integrity": "sha512-nGUvgXnotP3BsjiLX2ypbQnWoGUPIIfHQNZkkC668ntrzGWEZVW70HDEB1qnNGMicPje6EttlIgzo51YSwNQGw==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"cookie": "0.7.2",
|
|
||||||
"cookie-signature": "1.0.6"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.8.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/cookie-parser/node_modules/cookie": {
|
|
||||||
"version": "0.7.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
|
|
||||||
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
|
|
||||||
"license": "MIT",
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/cookie-signature": {
|
"node_modules/cookie-signature": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||||
|
|||||||
@@ -49,7 +49,6 @@
|
|||||||
"cache-manager-ioredis-yet": "^1.1.0",
|
"cache-manager-ioredis-yet": "^1.1.0",
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"class-validator": "^0.14.0",
|
"class-validator": "^0.14.0",
|
||||||
"cookie-parser": "^1.4.7",
|
|
||||||
"cron-parser": "^4.9.0",
|
"cron-parser": "^4.9.0",
|
||||||
"csv": "^6.3.11",
|
"csv": "^6.3.11",
|
||||||
"dotenv": "^14.3.2",
|
"dotenv": "^14.3.2",
|
||||||
@@ -78,7 +77,6 @@
|
|||||||
"multer": "1.4.5-lts.1"
|
"multer": "1.4.5-lts.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/cookie-parser": "^1.4.9",
|
|
||||||
"@types/cache-manager": "^4.0.6",
|
"@types/cache-manager": "^4.0.6",
|
||||||
"@types/express": "^4.17.17",
|
"@types/express": "^4.17.17",
|
||||||
"@types/express-session": "^1.18.1",
|
"@types/express-session": "^1.18.1",
|
||||||
|
|||||||
+1
-3
@@ -9,7 +9,6 @@ import { AppModule } from './app.module';
|
|||||||
import { writeFileSync } from 'fs';
|
import { writeFileSync } from 'fs';
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
import { INestApplication } from '@nestjs/common';
|
import { INestApplication } from '@nestjs/common';
|
||||||
import cookieParser from 'cookie-parser';
|
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
DadosferaLogger.setupLogger({
|
DadosferaLogger.setupLogger({
|
||||||
@@ -25,11 +24,10 @@ async function bootstrap() {
|
|||||||
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
||||||
preflightContinue: false,
|
preflightContinue: false,
|
||||||
optionsSuccessStatus: 204,
|
optionsSuccessStatus: 204,
|
||||||
credentials: true
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
app.use(cookieParser(process.env.COOKIE_SECRET));
|
|
||||||
if (process.env.ENV === 'prd') {
|
if (process.env.ENV === 'prd') {
|
||||||
app.use('/catalog/register-dataset', json({ limit: '10mb' }));
|
app.use('/catalog/register-dataset', json({ limit: '10mb' }));
|
||||||
app.use('/catalog/register-dataset', urlencoded({ extended: true, limit: '10mb' }));
|
app.use('/catalog/register-dataset', urlencoded({ extended: true, limit: '10mb' }));
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import {
|
|||||||
Redirect,
|
Redirect,
|
||||||
Req,
|
Req,
|
||||||
Param,
|
Param,
|
||||||
Res,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import {
|
import {
|
||||||
ApiHeaders,
|
ApiHeaders,
|
||||||
@@ -48,19 +47,12 @@ import {
|
|||||||
} from './dtos/login';
|
} from './dtos/login';
|
||||||
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/PackTheMetadata';
|
||||||
import { AuthGuard } from '@nestjs/passport';
|
import { AuthGuard } from '@nestjs/passport';
|
||||||
import { Request, Response } from 'express';
|
import { Request } from 'express';
|
||||||
import ErrorCodes, { OauthErrors } from 'src/utils/errorCodes';
|
import ErrorCodes, { OauthErrors } from 'src/utils/errorCodes';
|
||||||
import jwt, { JwtPayload } from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import { LanguageEnum } from 'src/utils/languages.enum';
|
import { LanguageEnum } from 'src/utils/languages.enum';
|
||||||
import { Language } from 'src/decorators/language.decorator';
|
import { Language } from 'src/decorators/language.decorator';
|
||||||
import { ApiInternalOnlyEndpoint } from 'src/decorators/swagger.decorator';
|
import { ApiInternalOnlyEndpoint } from 'src/decorators/swagger.decorator';
|
||||||
import { Cookie } from 'express-session';
|
|
||||||
|
|
||||||
type CookiesValues = {
|
|
||||||
accessToken?: string;
|
|
||||||
refreshToken?: string;
|
|
||||||
userId?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiTags('Auth')
|
@ApiTags('Auth')
|
||||||
@ApiHeaders([{ name: 'dadosfera-lang', enum: LanguageEnum, required: false }])
|
@ApiHeaders([{ name: 'dadosfera-lang', enum: LanguageEnum, required: false }])
|
||||||
@@ -94,65 +86,11 @@ export class AuthController {
|
|||||||
async signIn(
|
async signIn(
|
||||||
@Body() { username, password, totp }: AuthSignInReq,
|
@Body() { username, password, totp }: AuthSignInReq,
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
@Res() res: Response,
|
): Promise<AuthSignInRes> {
|
||||||
) {
|
this.logger.info('/auth - SignIn');
|
||||||
try {
|
const metadata = PackTheMetadata({ language });
|
||||||
this.logger.info('/auth - SignIn');
|
this.logger.info('metadata: ' + JSON.stringify(metadata.toJSON()));
|
||||||
const metadata = PackTheMetadata({ language });
|
return this.authClient.signIn({ username, password, totp }, metadata);
|
||||||
this.logger.info('metadata: ' + JSON.stringify(metadata.toJSON()));
|
|
||||||
const data = await this.authClient.signIn({ username, password, totp }, metadata);
|
|
||||||
|
|
||||||
if (data.tokens) {
|
|
||||||
this.addTokenInCookie(res, {
|
|
||||||
accessToken: data.tokens.accessToken,
|
|
||||||
refreshToken: data.tokens.refreshToken,
|
|
||||||
userId: data.user.id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return res.send(data);
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error('/auth - SignIn - ERROR', error);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('sign-out')
|
|
||||||
@HttpCode(HttpStatus.NO_CONTENT)
|
|
||||||
async signOut(
|
|
||||||
@Language() language: LanguageEnum,
|
|
||||||
@Res() res: Response,
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
this.logger.info('/auth - SignOut');
|
|
||||||
const exp = 1000 * 60 * 3;
|
|
||||||
|
|
||||||
res.cookie('ddf-auth', '', {
|
|
||||||
domain: 'dadosfera.local',
|
|
||||||
maxAge: Date.now() - exp,
|
|
||||||
expires: new Date(),
|
|
||||||
httpOnly: true,
|
|
||||||
secure: true,
|
|
||||||
sameSite: 'none', // Necessário para cookies em requisições cross-site
|
|
||||||
});
|
|
||||||
|
|
||||||
res.cookie('ddf-refresh-auth', '', {
|
|
||||||
domain: 'dadosfera.local',
|
|
||||||
maxAge: Date.now() - exp,
|
|
||||||
expires: new Date(),
|
|
||||||
httpOnly: true,
|
|
||||||
secure: true,
|
|
||||||
sameSite: 'none', // Necessário para cookies em requisições cross-site
|
|
||||||
});
|
|
||||||
|
|
||||||
this.logger.info('Clean cookie sessions');
|
|
||||||
|
|
||||||
return res.send();
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.error('/auth - SignIn - ERROR', error);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('refresh-access-token')
|
@Post('refresh-access-token')
|
||||||
@@ -162,25 +100,16 @@ export class AuthController {
|
|||||||
@Body() body: AuthRefreshAccessTokenReq,
|
@Body() body: AuthRefreshAccessTokenReq,
|
||||||
@Language() language: LanguageEnum,
|
@Language() language: LanguageEnum,
|
||||||
@Headers('origin') origin: string,
|
@Headers('origin') origin: string,
|
||||||
@Res() res: Response,
|
|
||||||
) {
|
) {
|
||||||
this.logger.info('/auth - RefreshAccessToken');
|
this.logger.info('/auth - RefreshAccessToken');
|
||||||
const frontHost = origin.replace(/^https?:\/\//, '');
|
|
||||||
const { refreshToken, userId } = body;
|
const { refreshToken, userId } = body;
|
||||||
|
const frontHost = origin.replace(/^https?:\/\//, '');
|
||||||
const metadata = PackTheMetadata({
|
const metadata = PackTheMetadata({
|
||||||
language,
|
language,
|
||||||
custom_host: frontHost,
|
custom_host: frontHost,
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await this.authClient.refreshAccessToken({ refreshToken, userId }, metadata);
|
return this.authClient.refreshAccessToken({ refreshToken, userId }, metadata);
|
||||||
|
|
||||||
this.addTokenInCookie(res, {
|
|
||||||
accessToken: data.accessToken,
|
|
||||||
userId
|
|
||||||
});
|
|
||||||
|
|
||||||
return res.send(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiInternalOnlyEndpoint()
|
@ApiInternalOnlyEndpoint()
|
||||||
@@ -489,117 +418,4 @@ export class AuthController {
|
|||||||
return this.authClient.resetUsers(body.users, metadata);
|
return this.authClient.resetUsers(body.users, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('me')
|
|
||||||
async getMe(@Req() req: Request, @Res() res: Response) {
|
|
||||||
this.logger.info('GET /auth/me ')
|
|
||||||
// Lê cookies
|
|
||||||
const accessToken = req.cookies['ddf-auth'];
|
|
||||||
const userId = req.cookies['ddf-user-id'];
|
|
||||||
|
|
||||||
this.logger.info('Has cookie: ' + Boolean(accessToken))
|
|
||||||
let payload: any;
|
|
||||||
let userInfo: any = {};
|
|
||||||
try {
|
|
||||||
// Decodifica e valida o JWT de acesso
|
|
||||||
const decoded: any = accessToken && jwt.decode(accessToken, { complete: true });
|
|
||||||
if (!decoded) throw new Error('Invalid token')
|
|
||||||
const { kid } = decoded.header;
|
|
||||||
// Busca a chave pública
|
|
||||||
const { keys } = await this.authClient.getPublicKeys();
|
|
||||||
const pemValue = keys.find((k) => k.kid === kid)?.pem;
|
|
||||||
if (!pemValue) throw new Error('Public key not found');
|
|
||||||
jwt.verify(accessToken, pemValue);
|
|
||||||
payload = decoded.payload;
|
|
||||||
userInfo = {
|
|
||||||
id: payload.user_id,
|
|
||||||
name: payload.username,
|
|
||||||
customer: {
|
|
||||||
id: payload.customer_id,
|
|
||||||
name: payload.customer_name,
|
|
||||||
tier: payload.customer_tier,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return res.status(200).json(userInfo);
|
|
||||||
} catch (err) {
|
|
||||||
this.logger.error(err.message);
|
|
||||||
const refreshToken = req.cookies['ddf-refresh-auth'];
|
|
||||||
|
|
||||||
this.logger.info('Token is invalid')
|
|
||||||
this.logger.info('Has Refresh Token: '+ Boolean(refreshToken))
|
|
||||||
// Se access token inválido, tenta refresh
|
|
||||||
if (!refreshToken || !userId) {
|
|
||||||
this.logger.error('Invalid refresh token or customer name');
|
|
||||||
return res.status(401).json({ error: 'Not authenticated' });
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
// Chama refreshAccessToken
|
|
||||||
const metadata = PackTheMetadata({
|
|
||||||
});
|
|
||||||
this.logger.info('Call Refresh Token')
|
|
||||||
const data = await this.authClient.refreshAccessToken({ refreshToken, userId }, metadata);
|
|
||||||
this.logger.info('Finish Refresh Token')
|
|
||||||
// Retorna novo access token e dados mínimos
|
|
||||||
this.addTokenInCookie(res, {
|
|
||||||
accessToken: data.accessToken,
|
|
||||||
userId
|
|
||||||
});
|
|
||||||
// Decodifica novo token
|
|
||||||
const decoded: any = jwt.decode(data.accessToken, { complete: true });
|
|
||||||
const payload = decoded.payload;
|
|
||||||
userInfo = {
|
|
||||||
id: payload.user_id,
|
|
||||||
name: payload.username,
|
|
||||||
customer: {
|
|
||||||
id: payload.customer_id,
|
|
||||||
name: payload.customer_name,
|
|
||||||
tier: payload.customer_tier,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return res.status(200).json(userInfo);
|
|
||||||
} catch (refreshErr) {
|
|
||||||
this.logger.error(refreshErr)
|
|
||||||
return res.status(401).json({ error: 'Not authenticated' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private addTokenInCookie(res: Response, data: CookiesValues) {
|
|
||||||
let exp = 1000 * 60 * 5; // 5 minutes
|
|
||||||
|
|
||||||
if (data.accessToken) {
|
|
||||||
const { exp: expiration } = jwt.decode(data.accessToken) as JwtPayload;
|
|
||||||
exp = (expiration - 30) * 1000; // exp em segundos, maxAge em ms
|
|
||||||
|
|
||||||
this.logger.info('Set Cookie ddf-auth')
|
|
||||||
res.cookie('ddf-auth', data.accessToken, {
|
|
||||||
domain: 'stg.dadosfera.ai',
|
|
||||||
maxAge: exp,
|
|
||||||
httpOnly: true,
|
|
||||||
secure: true,
|
|
||||||
sameSite: 'none', // Necessário para cookies em requisições cross-site
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.refreshToken) {
|
|
||||||
this.logger.info('Set Cookie ddf-refresh-auth')
|
|
||||||
res.cookie('ddf-refresh-auth', data.refreshToken, {
|
|
||||||
domain: 'stg.dadosfera.ai',
|
|
||||||
maxAge: exp,
|
|
||||||
httpOnly: true,
|
|
||||||
secure: true,
|
|
||||||
sameSite: 'none', // Necessário para cookies em requisições cross-site
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.userId) {
|
|
||||||
this.logger.info('Set Cookie ddf-refresh-auth')
|
|
||||||
res.cookie('ddf-user-id', data.userId, {
|
|
||||||
domain: 'stg.dadosfera.ai',
|
|
||||||
maxAge: exp,
|
|
||||||
httpOnly: true,
|
|
||||||
secure: true,
|
|
||||||
sameSite: 'none', // Necessário para cookies em requisições cross-site
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user