@loopback/authorization
Version:
A LoopBack component for authorization support.
32 lines • 1.32 kB
JavaScript
;
// Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
// Node module: @loopback/authorization
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPrincipalFromUserProfile = void 0;
const security_1 = require("@loopback/security");
// This is a workaround before we specify `TypedPrincipal` instead of
// `Principal` for the principals in the authorization context.
/**
* Module `@loopback/authentication` passes a user profile to
* `@loopback/authorization` as the user identity. Authorization verifies
* whether a user has access to a certain resource.
*
* The builder function:
* - preserves all the fields from user profile
* - specifies 'USER' as type
* - assign the value of `securityId` to name if it's missing in the
* user profile
* @param user The user profile passed from `@loopback/authentication`.
*/
function createPrincipalFromUserProfile(user) {
var _a;
return {
...user,
name: (_a = user.name) !== null && _a !== void 0 ? _a : user[security_1.securityId],
type: 'USER',
};
}
exports.createPrincipalFromUserProfile = createPrincipalFromUserProfile;
//# sourceMappingURL=util.js.map