@amsame/kinde-auth-nestjs
Advanced tools
Comparing version 1.0.14 to 1.1.0
@@ -25,2 +25,14 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -30,10 +42,21 @@ exports.KindeUser = void 0; | ||
const common_1 = require("@nestjs/common"); | ||
exports.KindeUser = (0, common_1.createParamDecorator)((data, ctx) => { | ||
const kinde_factory_1 = require("../lib/kinde.factory"); | ||
const kinde_constant_1 = require("../lib/kinde.constant"); | ||
const axios_1 = __importDefault(require("axios")); | ||
exports.KindeUser = (0, common_1.createParamDecorator)((data, ctx) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _a; | ||
try { | ||
const request = ctx.switchToHttp().getRequest(); | ||
const cookies = cookie.parse(request.headers.cookie || ''); | ||
if (!cookies['user']) | ||
return null; | ||
const user = JSON.parse(cookies['user']); | ||
return data ? user === null || user === void 0 ? void 0 : user[data] : user; | ||
const token = (_a = cookies[kinde_constant_1.KINDE_ACCESS_TOKEN]) !== null && _a !== void 0 ? _a : null; | ||
const headers = { | ||
Accept: 'application/json', | ||
Authorization: `Bearer ${token}`, | ||
}; | ||
const profile = yield axios_1.default.get(`${(0, kinde_factory_1.getEnvSafely)(kinde_constant_1.KINDE_DOMAIN_URL)}/oauth2/user_profile`, { | ||
headers, | ||
}); | ||
if (profile.status === 200) { | ||
return profile.data; | ||
} | ||
} | ||
@@ -43,2 +66,2 @@ catch (error) { | ||
} | ||
}); | ||
})); |
import { KindePayload } from '../lib/kinde.interface'; | ||
import { CanActivate, ExecutionContext } from '@nestjs/common'; | ||
export declare abstract class AbstractGuard implements CanActivate { | ||
private readonly AUD; | ||
constructor(); | ||
/** | ||
@@ -7,0 +5,0 @@ * Determines if the user is authorized to access a route. |
@@ -9,12 +9,5 @@ "use strict"; | ||
const jwks_rsa_1 = __importDefault(require("jwks-rsa")); | ||
const getEnvSafely = (envKey) => { | ||
const envVal = process.env[envKey]; | ||
if (!envVal) | ||
throw new Error(`Missing env variable ${envKey}!`); | ||
return envVal; | ||
}; | ||
const kinde_factory_1 = require("../lib/kinde.factory"); | ||
const kinde_constant_1 = require("../lib/kinde.constant"); | ||
class AbstractGuard { | ||
constructor() { | ||
this.AUD = getEnvSafely('KINDE_AUDIENCE'); | ||
} | ||
/** | ||
@@ -27,3 +20,3 @@ * Retrieves the signing key from the JwksClient based on the provided header. | ||
const client = (0, jwks_rsa_1.default)({ | ||
jwksUri: `${getEnvSafely('KINDE_DOMAIN_URL')}/.well-known/jwks`, | ||
jwksUri: `${(0, kinde_factory_1.getEnvSafely)(kinde_constant_1.KINDE_DOMAIN_URL)}/.well-known/jwks`, | ||
}); | ||
@@ -43,3 +36,3 @@ client.getSigningKey(header.kid, function (err, key) { | ||
return reject(new Error('No JWT token provided!')); | ||
jsonwebtoken_1.default.verify(token, this.getKey, { audience: this.AUD }, (err, decoded) => { | ||
jsonwebtoken_1.default.verify(token, this.getKey, {}, (err, decoded) => { | ||
if (err) | ||
@@ -46,0 +39,0 @@ reject(err); |
@@ -50,2 +50,3 @@ "use strict"; | ||
const auth_decorator_1 = require("../decorators/auth.decorator"); | ||
const kinde_constant_1 = require("../lib/kinde.constant"); | ||
let IsAuthGuard = class IsAuthGuard extends abstract_guard_1.AbstractGuard { | ||
@@ -65,3 +66,3 @@ constructor(reflector) { | ||
const cookies = cookie.parse(request.headers.cookie || ''); | ||
const decoded = yield this.verifyToken(cookies['access_token']); | ||
const decoded = yield this.verifyToken(cookies[kinde_constant_1.KINDE_ACCESS_TOKEN]); | ||
if (!decoded) { | ||
@@ -68,0 +69,0 @@ throw new common_1.UnauthorizedException(); |
@@ -50,2 +50,3 @@ "use strict"; | ||
const permissions_decorator_1 = require("../decorators/permissions.decorator"); | ||
const kinde_constant_1 = require("../lib/kinde.constant"); | ||
let PermissionsGuard = class PermissionsGuard extends abstract_guard_1.AbstractGuard { | ||
@@ -65,3 +66,3 @@ constructor(reflector) { | ||
const cookies = cookie.parse(request.headers.cookie || ''); | ||
const decoded = yield this.verifyToken(cookies['access_token']); | ||
const decoded = yield this.verifyToken(cookies[kinde_constant_1.KINDE_ACCESS_TOKEN]); | ||
if (!decoded) { | ||
@@ -68,0 +69,0 @@ throw new common_1.UnauthorizedException(); |
@@ -50,2 +50,3 @@ "use strict"; | ||
const roles_decorator_1 = require("../decorators/roles.decorator"); | ||
const kinde_constant_1 = require("../lib/kinde.constant"); | ||
let RolesGuard = class RolesGuard extends abstract_guard_1.AbstractGuard { | ||
@@ -66,3 +67,3 @@ constructor(reflector) { | ||
const cookies = cookie.parse(request.headers.cookie || ''); | ||
const decoded = yield this.verifyToken(cookies['access_token']); | ||
const decoded = yield this.verifyToken(cookies[kinde_constant_1.KINDE_ACCESS_TOKEN]); | ||
if (!decoded) { | ||
@@ -69,0 +70,0 @@ throw new common_1.UnauthorizedException(); |
export declare const KINDE_MODULE_OPTIONS = "KINDE_MODULE_OPTIONS"; | ||
export declare const KINDE_DOMAIN_URL = "KINDE_DOMAIN_URL"; | ||
export declare const KINDE_ACCESS_TOKEN = "access_token"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.KINDE_MODULE_OPTIONS = void 0; | ||
exports.KINDE_ACCESS_TOKEN = exports.KINDE_DOMAIN_URL = exports.KINDE_MODULE_OPTIONS = void 0; | ||
exports.KINDE_MODULE_OPTIONS = 'KINDE_MODULE_OPTIONS'; | ||
exports.KINDE_DOMAIN_URL = 'KINDE_DOMAIN_URL'; | ||
exports.KINDE_ACCESS_TOKEN = 'access_token'; |
import { Provider } from '@nestjs/common'; | ||
import { KindeModuleOptions } from './kinde.interface'; | ||
export declare function createKindeProvider(options: KindeModuleOptions): Provider[]; | ||
export declare const getEnvSafely: (envKey: string) => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createKindeProvider = void 0; | ||
exports.getEnvSafely = exports.createKindeProvider = void 0; | ||
const kinde_constant_1 = require("./kinde.constant"); | ||
@@ -9,1 +9,8 @@ function createKindeProvider(options) { | ||
exports.createKindeProvider = createKindeProvider; | ||
const getEnvSafely = (envKey) => { | ||
const envVal = process.env[envKey]; | ||
if (!envVal) | ||
throw new Error(`Missing env variable ${envKey}!`); | ||
return envVal; | ||
}; | ||
exports.getEnvSafely = getEnvSafely; |
@@ -65,7 +65,9 @@ import { InjectionToken, ModuleMetadata, OptionalFactoryDependency, Provider, Type } from '@nestjs/common'; | ||
export type IKindeUser = { | ||
family_name: string | null; | ||
given_name: string | null; | ||
picture: string | null; | ||
email: string; | ||
id: string; | ||
preferred_email: string; | ||
username: string; | ||
provided_id: string; | ||
last_name: string; | ||
first_name: string; | ||
picture: string; | ||
}; |
{ | ||
"name": "@amsame/kinde-auth-nestjs", | ||
"version": "1.0.14", | ||
"version": "1.1.0", | ||
"description": "Kinde Auth module for NestJS framework", | ||
@@ -45,2 +45,3 @@ "author": { | ||
"dependencies": { | ||
"axios": "^1.7.2", | ||
"cookie": "^0.6.0", | ||
@@ -50,3 +51,3 @@ "jsonwebtoken": "^9.0.2", | ||
"reflect-metadata": "^0.2.2", | ||
"tslib": "^2.6.0" | ||
"tslib": "^2.6.2" | ||
}, | ||
@@ -53,0 +54,0 @@ "peerDependencies": { |
37632
675
9
+ Addedaxios@^1.7.2
+ Addedasynckit@0.4.0(transitive)
+ Addedaxios@1.7.9(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedproxy-from-env@1.1.0(transitive)
Updatedtslib@^2.6.2