我正在使用var app = angular.module('plunker', []);
app.service('myService', function() {
var my = this;
my.name = "original";
});
app.controller('MainCtrl', function(myService) {
var mv = this;
mv.name = myService.name;
});
app.controller('MainCtrl2', function(myService) {
var mv = this;
mv.name = myService.name;
mv.setN = function(a) {
myService.name = a;
};
});
插件进行api身份验证,使用hapi-auth-bearer-token
。
这是我的代码:
hapijs
这是我得到的错误:
apiServer.register(require('hapi-auth-bearer-token'), function (err) {
server.auth.strategy('simple', 'bearer-access-token', {
allowQueryToken: true, // optional, true by default
allowMultipleHeaders: false, // optional, false by default
accessTokenName: 'access_token', // optional, 'access_token' by default
validateFunc: function( token, callback ) {
// For convenience, the request object can be accessed
// from `this` within validateFunc.
var request = this;
// Use a real strategy here,
// comparing with a token from your database for example
if(token === "1234"){
//## user object to be looked up here
callback(null, true, { token: token })
} else {
callback(null, false, { token: token })
}
}
});
});
该消息是简单的英语,但我不明白我必须添加到我的代码来解决问题。
答案 0 :(得分:3)
看起来您正在一台服务器上注册hapi-auth-bearer-token
插件(apiServer
),然后在另一台服务器上设置auth策略(server
)
尝试
apiServer.register(require('hapi-auth-bearer-token'), function (err) {
apiServer.auth.strategy('simple', 'bearer-access-token', {
allowQueryToken: true, // optional, true by default
allowMultipleHeaders: false, // optional, false by default
accessTokenName: 'access_token', // optional, 'access_token' by default
validateFunc: function( token, callback ) {
// For convenience, the request object can be accessed
// from `this` within validateFunc.
var request = this;
// Use a real strategy here,
// comparing with a token from your database for example
if(token === "1234"){
//## user object to be looked up here
callback(null, true, { token: token })
} else {
callback(null, false, { token: token })
}
}
});
});