本文整理汇总了TypeScript中@feathersjs/authentication.AuthenticationService.register方法的典型用法代码示例。如果您正苦于以下问题:TypeScript AuthenticationService.register方法的具体用法?TypeScript AuthenticationService.register怎么用?TypeScript AuthenticationService.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@feathersjs/authentication.AuthenticationService
的用法示例。
在下文中一共展示了AuthenticationService.register方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: default
export default (app: Application) => {
const authentication = new AuthenticationService(app);
app.set('authentication', {
entity: 'user',
service: 'users',
secret: 'supersecret',
authStrategies: [ 'local', 'jwt' ],
local: {
usernameField: 'email',
passwordField: 'password'
}
});
authentication.register('jwt', new JWTStrategy());
authentication.register('local', new LocalStrategy());
app.use('/authentication', authentication);
app.use('/users', memory({
paginate: {
default: 10,
max: 20
}
}));
app.service('users').hooks({
before: {
create: hashPassword('password')
},
after: protect('password')
});
app.use('/dummy', {
find (params) {
return Promise.resolve(params);
}
});
app.service('dummy').hooks({
before: authenticate('jwt')
});
app.service('users').hooks({
before (context: HookContext) {
if (context.id !== undefined && context.id !== null) {
context.id = parseInt(context.id as string, 10);
}
return context;
}
});
return app;
};
示例2: each
each(grant, (value, key) => {
if (key !== 'defaults') {
value.callback = value.callback || `${path}/${key}/authenticate`;
if (!strategyNames.includes(key)) {
debug(`Registering oAuth default strategy for '${key}'`);
service.register(key, new OAuthStrategy());
}
}
});
示例3: getProfile
export class TestOAuthStrategy extends OAuthStrategy {
async getProfile (data: AuthenticationRequest, _params: Params) {
if (!data.id) {
throw new Error('Data needs an id');
}
return data;
}
}
const port = 3000;
const app = express(feathers());
const auth = new AuthenticationService(app);
auth.register('jwt', new JWTStrategy());
auth.register('test', new TestOAuthStrategy());
app.configure(rest());
app.set('host', '127.0.0.1');
app.set('port', port);
app.set('authentication', {
secret: 'supersecret',
entity: 'user',
service: 'users',
authStrategies: [ 'jwt' ],
oauth: {
defaults: {
transport: 'query'
},
test: {