@ghentcdh/authentication-api 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/package.json +20 -0
- package/src/index.d.ts +3 -0
- package/src/index.js +7 -0
- package/src/index.js.map +1 -0
- package/src/lib/auth.const.d.ts +4 -0
- package/src/lib/auth.const.js +8 -0
- package/src/lib/auth.const.js.map +1 -0
- package/src/lib/auth.guard.d.ts +11 -0
- package/src/lib/auth.guard.js +52 -0
- package/src/lib/auth.guard.js.map +1 -0
- package/src/lib/authentication-api.module.d.ts +2 -0
- package/src/lib/authentication-api.module.js +20 -0
- package/src/lib/authentication-api.module.js.map +1 -0
- package/src/lib/login.controller.d.ts +6 -0
- package/src/lib/login.controller.js +37 -0
- package/src/lib/login.controller.js.map +1 -0
- package/src/lib/user.d.ts +2 -0
- package/src/lib/user.js +11 -0
- package/src/lib/user.js.map +1 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ghentcdh/authentication-api",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "commonjs",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"tslib": "^2.3.0",
|
|
9
|
+
"@nestjs/common": "^10.0.2",
|
|
10
|
+
"@nestjs/axios": "^4.0.0",
|
|
11
|
+
"@nestjs/config": "^4.0.0",
|
|
12
|
+
"rxjs": "^7.8.0",
|
|
13
|
+
"@nestjs/swagger": "^11.0.4"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/GhentCDH/ghentcdh-monorepo.git",
|
|
18
|
+
"directory": "libs/authentication/api"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./lib/authentication-api.module"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./lib/auth.guard"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/auth.const"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/authentication/api/src/index.ts"],"names":[],"mappings":";;;AAAA,0EAAgD;AAChD,2DAAiC;AACjC,2DAAgC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.const.js","sourceRoot":"","sources":["../../../../../../libs/authentication/api/src/lib/auth.const.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG;IACrB,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,gBAAgB;CACjB,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HttpService } from '@nestjs/axios';
|
|
2
|
+
import type { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
4
|
+
import type { Observable } from 'rxjs';
|
|
5
|
+
export declare const AUTH_NAME = "keycloack";
|
|
6
|
+
export declare class GhentCdhGuard implements CanActivate {
|
|
7
|
+
private readonly httpService;
|
|
8
|
+
private readonly configService;
|
|
9
|
+
constructor(httpService: HttpService, configService: ConfigService);
|
|
10
|
+
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GhentCdhGuard = exports.AUTH_NAME = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const axios_1 = require("@nestjs/axios");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const config_1 = require("@nestjs/config");
|
|
8
|
+
const rxjs_1 = require("rxjs");
|
|
9
|
+
const auth_const_1 = require("./auth.const");
|
|
10
|
+
exports.AUTH_NAME = 'keycloack';
|
|
11
|
+
let GhentCdhGuard = class GhentCdhGuard {
|
|
12
|
+
constructor(httpService, configService) {
|
|
13
|
+
this.httpService = httpService;
|
|
14
|
+
this.configService = configService;
|
|
15
|
+
}
|
|
16
|
+
canActivate(context) {
|
|
17
|
+
const request = context.switchToHttp().getRequest();
|
|
18
|
+
const authorization = request.headers.authorization;
|
|
19
|
+
if (authorization) {
|
|
20
|
+
const keycloakHost = this.configService.get(auth_const_1.KEYCLOACK.HOST);
|
|
21
|
+
const realmName = this.configService.get(auth_const_1.KEYCLOACK.REALM);
|
|
22
|
+
const url = `${keycloakHost}realms/${realmName}/protocol/openid-connect/userinfo`;
|
|
23
|
+
return (0, rxjs_1.firstValueFrom)(this.httpService.get(url, {
|
|
24
|
+
headers: {
|
|
25
|
+
// add the token you received to the userinfo request, sent to keycloak
|
|
26
|
+
Authorization: authorization,
|
|
27
|
+
' X-Forwarded-Host': 'localhost:8080',
|
|
28
|
+
},
|
|
29
|
+
}))
|
|
30
|
+
.then((response) => {
|
|
31
|
+
// if the request status isn't "OK", the token is invalid
|
|
32
|
+
if (response.status !== 200) {
|
|
33
|
+
throw new common_1.UnauthorizedException();
|
|
34
|
+
}
|
|
35
|
+
// the token is valid pass request onto your next function
|
|
36
|
+
request.user = response.data;
|
|
37
|
+
return true;
|
|
38
|
+
})
|
|
39
|
+
.catch((error) => {
|
|
40
|
+
throw new common_1.UnauthorizedException();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
throw new common_1.UnauthorizedException();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.GhentCdhGuard = GhentCdhGuard;
|
|
47
|
+
exports.GhentCdhGuard = GhentCdhGuard = tslib_1.__decorate([
|
|
48
|
+
(0, common_1.Injectable)(),
|
|
49
|
+
tslib_1.__metadata("design:paramtypes", [axios_1.HttpService,
|
|
50
|
+
config_1.ConfigService])
|
|
51
|
+
], GhentCdhGuard);
|
|
52
|
+
//# sourceMappingURL=auth.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.guard.js","sourceRoot":"","sources":["../../../../../../libs/authentication/api/src/lib/auth.guard.ts"],"names":[],"mappings":";;;;AACA,yCAA6C;AAE7C,2CAAmE;AACnE,2CAAgD;AAEhD,+BAAsC;AAGtC,6CAAyC;AAE5B,QAAA,SAAS,GAAG,WAAW,CAAC;AAG9B,IAAM,aAAa,GAAnB,MAAM,aAAa;IACxB,YACmB,WAAwB,EACxB,aAA4B;QAD5B,gBAAW,GAAX,WAAW,CAAa;QACxB,kBAAa,GAAb,aAAa,CAAe;IAC5C,CAAC;IAEJ,WAAW,CACT,OAAyB;QAEzB,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QAEpD,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC;QAEpD,IAAI,aAAa,EAAE,CAAC;YAClB,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,sBAAS,CAAC,IAAI,CAAC,CAAC;YAC5D,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,sBAAS,CAAC,KAAK,CAAC,CAAC;YAG1D,MAAM,GAAG,GAAG,GAAG,YAAY,UAAU,SAAS,mCAAmC,CAAC;YAElF,OAAO,IAAA,qBAAc,EACnB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE;gBACxB,OAAO,EAAE;oBACP,uEAAuE;oBACvE,aAAa,EAAE,aAAa;oBAC5B,mBAAmB,EAAE,gBAAgB;iBACtC;aACF,CAAC,CACH;iBACE,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACjB,yDAAyD;gBACzD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;oBAC5B,MAAM,IAAI,8BAAqB,EAAE,CAAC;gBACpC,CAAC;gBAED,0DAA0D;gBAC1D,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;gBAE7B,OAAO,IAAI,CAAC;YACd,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBACf,MAAM,IAAI,8BAAqB,EAAE,CAAC;YACpC,CAAC,CAAC,CAAC;QACP,CAAC;QAED,MAAM,IAAI,8BAAqB,EAAE,CAAC;IACpC,CAAC;CACF,CAAA;AA/CY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;6CAGqB,mBAAW;QACT,sBAAa;GAHpC,aAAa,CA+CzB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthenticationApiModule = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const axios_1 = require("@nestjs/axios");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const config_1 = require("@nestjs/config");
|
|
8
|
+
const login_controller_1 = require("./login.controller");
|
|
9
|
+
let AuthenticationApiModule = class AuthenticationApiModule {
|
|
10
|
+
};
|
|
11
|
+
exports.AuthenticationApiModule = AuthenticationApiModule;
|
|
12
|
+
exports.AuthenticationApiModule = AuthenticationApiModule = tslib_1.__decorate([
|
|
13
|
+
(0, common_1.Module)({
|
|
14
|
+
imports: [axios_1.HttpModule, config_1.ConfigModule],
|
|
15
|
+
controllers: [login_controller_1.LoginController],
|
|
16
|
+
providers: [],
|
|
17
|
+
exports: [],
|
|
18
|
+
})
|
|
19
|
+
], AuthenticationApiModule);
|
|
20
|
+
//# sourceMappingURL=authentication-api.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication-api.module.js","sourceRoot":"","sources":["../../../../../../libs/authentication/api/src/lib/authentication-api.module.ts"],"names":[],"mappings":";;;;AAAA,yCAA2C;AAC3C,2CAAwC;AACxC,2CAA8C;AAE9C,yDAAqD;AAQ9C,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;CAAG,CAAA;AAA1B,0DAAuB;kCAAvB,uBAAuB;IANnC,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,kBAAU,EAAE,qBAAY,CAAC;QACnC,WAAW,EAAE,CAAC,kCAAe,CAAC;QAC9B,SAAS,EAAE,EAAE;QACb,OAAO,EAAE,EAAE;KACZ,CAAC;GACW,uBAAuB,CAAG"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoginController = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
7
|
+
const auth_guard_1 = require("./auth.guard");
|
|
8
|
+
const user_1 = require("./user");
|
|
9
|
+
let LoginController = class LoginController {
|
|
10
|
+
async login(user, req) {
|
|
11
|
+
return user;
|
|
12
|
+
}
|
|
13
|
+
getLogin() {
|
|
14
|
+
return { test: 'Login abc' };
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.LoginController = LoginController;
|
|
18
|
+
tslib_1.__decorate([
|
|
19
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
20
|
+
(0, common_1.UseGuards)(auth_guard_1.GhentCdhGuard),
|
|
21
|
+
(0, common_1.Post)('auth/login'),
|
|
22
|
+
tslib_1.__param(0, (0, user_1.User)()),
|
|
23
|
+
tslib_1.__param(1, (0, common_1.Request)()),
|
|
24
|
+
tslib_1.__metadata("design:type", Function),
|
|
25
|
+
tslib_1.__metadata("design:paramtypes", [Object, Object]),
|
|
26
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
27
|
+
], LoginController.prototype, "login", null);
|
|
28
|
+
tslib_1.__decorate([
|
|
29
|
+
(0, common_1.Get)('auth/login'),
|
|
30
|
+
tslib_1.__metadata("design:type", Function),
|
|
31
|
+
tslib_1.__metadata("design:paramtypes", []),
|
|
32
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
33
|
+
], LoginController.prototype, "getLogin", null);
|
|
34
|
+
exports.LoginController = LoginController = tslib_1.__decorate([
|
|
35
|
+
(0, common_1.Controller)()
|
|
36
|
+
], LoginController);
|
|
37
|
+
//# sourceMappingURL=login.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.controller.js","sourceRoot":"","sources":["../../../../../../libs/authentication/api/src/lib/login.controller.ts"],"names":[],"mappings":";;;;AAAA,2CAA2E;AAC3E,6CAAgD;AAEhD,6CAA6C;AAC7C,iCAA8B;AAGvB,IAAM,eAAe,GAArB,MAAM,eAAe;IAIpB,AAAN,KAAK,CAAC,KAAK,CAAS,IAAS,EAAa,GAAQ;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;IAGD,QAAQ;QACN,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAC/B,CAAC;CACF,CAAA;AAZY,0CAAe;AAIpB;IAHL,IAAA,uBAAa,GAAE;IACf,IAAA,kBAAS,EAAC,0BAAa,CAAC;IACxB,IAAA,aAAI,EAAC,YAAY,CAAC;IACN,mBAAA,IAAA,WAAI,GAAE,CAAA;IAAa,mBAAA,IAAA,gBAAO,GAAE,CAAA;;;;4CAExC;AAGD;IADC,IAAA,YAAG,EAAC,YAAY,CAAC;;;;+CAGjB;0BAXU,eAAe;IAD3B,IAAA,mBAAU,GAAE;GACA,eAAe,CAY3B"}
|
package/src/lib/user.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.User = exports.Roles = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const Roles = (...roles) => (0, common_1.SetMetadata)('roles', roles);
|
|
6
|
+
exports.Roles = Roles;
|
|
7
|
+
exports.User = (0, common_1.createParamDecorator)((_data, ctx) => {
|
|
8
|
+
const request = ctx.switchToHttp().getRequest();
|
|
9
|
+
return request.user;
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../../../../libs/authentication/api/src/lib/user.ts"],"names":[],"mappings":";;;AACA,2CAAiE;AAG1D,MAAM,KAAK,GAAG,CAAC,GAAG,KAAe,EAAE,EAAE,CAAC,IAAA,oBAAW,EAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAA5D,QAAA,KAAK,SAAuD;AAE5D,QAAA,IAAI,GAAG,IAAA,6BAAoB,EAAC,CAAC,KAAc,EAAE,GAAqB,EAAE,EAAE;IAC/E,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IAEhD,OAAO,OAAO,CAAC,IAAI,CAAC;AACxB,CAAC,CAAC,CAAC"}
|