UNPKG

@shrinedev/loopback-keycloak-demo-app

Version:

Example Loopback App that integrates with Keycloak.

76 lines 2.95 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); const rest_1 = require("@loopback/rest"); const context_1 = require("@loopback/context"); const loopback_gate_keycloak_1 = require("@shrinedev/loopback-gate-keycloak"); const loopback_gate_1 = require("@shrinedev/loopback-gate"); /** * OpenAPI response for me() */ const ME_RESPONSE = { description: '/me Current User Response', content: { 'application/json': { schema: { type: 'object', properties: { email: { type: 'string' }, username: { type: 'string' }, id: { type: 'string' }, teams: { type: 'array', items: { type: 'string', }, }, }, }, }, }, }; /** * A controller to demonstrate a LoopBack Keycloak Gate */ let UserController = class UserController { constructor() { } // Map to `GET /me` me(user) { // Reply with a current user authorized by Keycloak return { email: user && user.email, id: user && user.id, name: user && user.name, teams: user && user.teams, }; } }; __decorate([ loopback_gate_1.gateWith(loopback_gate_keycloak_1.KeycloakGate, loopback_gate_1.LogGate), rest_1.get('/auth/me', { responses: { '200': ME_RESPONSE, }, }), __param(0, context_1.inject(loopback_gate_keycloak_1.KeycloakBindings.CURRENT_USER)), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Object) ], UserController.prototype, "me", null); UserController = __decorate([ loopback_gate_1.gateAllWith(loopback_gate_1.LogGate), __metadata("design:paramtypes", []) ], UserController); exports.UserController = UserController; //# sourceMappingURL=user.controller.js.map