1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
3 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
4 # you may not use this file except in compliance with the License. #
\r
5 # You may obtain a copy of the License at #
\r
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
9 # Unless required by applicable law or agreed to in writing, software #
\r
10 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
12 # See the License for the specific language governing permissions and #
\r
13 # limitations under the License. #
\r
14 ##############################################################################*/
\r
17 const authentication = require('@feathersjs/authentication');
\r
18 const jwt = require('@feathersjs/authentication-jwt');
\r
19 const local = require('@feathersjs/authentication-local');
\r
20 const { permissions } = require('./hooks/permissions/permissions');
\r
21 // const { hashPassword, protect } = require('@feathersjs/authentication-local').hooks;
\r
23 module.exports = function (app) {
\r
24 const config = app.get('authentication');
\r
26 // Set up authentication with the secret
\r
27 app.configure(authentication(config));
\r
28 app.configure(jwt());
\r
29 app.configure(local());
\r
31 // The `authentication` service is used to create a JWT.
\r
32 // The before `create` hook registers strategies that can be used
\r
33 // to create a new valid JWT (e.g. local or oauth2)
\r
34 app.service(config.path).hooks({
\r
38 //console.log(context.data)
\r
39 // console.log('authing');
\r
41 authentication.hooks.authenticate(config.strategies),
\r
42 permissions('authentication')
\r
45 authentication.hooks.authenticate('jwt')
\r
50 // Send the user profile back with access token
\r
51 async function (context) {
\r
52 if (!context.params.user.enabled) {
\r
53 context.result.accessToken = null;
\r
56 context.result['user'] = context.params.user;
\r
58 //Send Back the users rules
\r
59 if(context.params.ability){
\r
60 context.result.user['rules'] = context.params.ability.rules;
\r
63 delete context.result.user.password;
\r