我尝试使用EQUIP4创建自定义身份验证我有参考:https://loopback.io/doc/en/lb4/Implement-your-own-strategy.html services.authentication.basic.user.service未绑定
这是user.controller
,我注入了JWTAuthenticationStrategyBindings
,BasicAuthenticationStrategyBindings
import {
authenticate,
TokenService,
AuthenticationBindings,
} from '@loopback/authentication';
import {inject, Getter} from '@loopback/core';
import {model, property, repository} from '@loopback/repository';
import {
get,
getModelSchemaRef,
post,
requestBody,
SchemaObject,
} from '@loopback/rest';
import {SecurityBindings, securityId, UserProfile} from '@loopback/security';
import {genSalt, hash} from 'bcryptjs';
import _ from 'lodash';
import {User} from '../models';
import {UserRepository} from '../customStrategy/__tests__/fixtures/users/user.repository';
import {BasicAuthenticationUserService} from '../customStrategy/__tests__/fixtures/services/basic-auth-user-service';
import {
BasicAuthenticationStrategyBindings,
JWTAuthenticationStrategyBindings,
} from '../customStrategy/__tests__/fixtures/keys';
export class UserController {
constructor(
@inject(JWTAuthenticationStrategyBindings.TOKEN_SERVICE)
public jwtService: TokenService,
@inject(BasicAuthenticationStrategyBindings.USER_SERVICE)
public userService: BasicAuthenticationUserService,
@inject(SecurityBindings.USER, {optional: true})
public user: UserProfile,
@repository(UserRepository) protected userRepository: UserRepository,
) {}
@get('/auth/me', {
responses: {
'200': {
description: 'The current user profile',
content: {
'application/json': {
schema: CredentialsSchema,
},
},
},
},
})
@authenticate('basic')
async printCurrentUser(
@inject('authentication.currentUser') user: UserProfile,
): Promise<UserProfile> {
return user;
}
}
我是2014年的新手,我想为我的新项目创建自定义身份验证。所以我尝试为我下一个项目创建虚拟项目。
1条答案
按热度按时间bnlyeluc1#
我已经解决了这个错误我们只需要在上下文中添加绑定
application.ts
注意:以上代码添加到构造函数中