带适配器的认证工作灯推送通知不起作用 [英] Worklight Push notification with Adapter Authentication doesn't work
问题描述
我用我的工作灯测试应用程序推送通知。我已经通过工作灯适配器取得认证。但这种方式,我总是收到来自PushAdapter响应没有找到订阅用户:: [sample_username]
设备进行认证:
和我的测试Android设备被认购通知。
我的简单AuthAdapter:
函数onAuthRequired(头,的errorMessage){
的errorMessage =的errorMessage?的errorMessage:空;
返回{
authRequired:真实,
的errorMessage:的errorMessage
};
}
功能submitAuthentication(用户名,密码){
VAR的UserIdentity = {
用户名:用户名,
显示名:用户名,
属性:{
富:栏
}
};
WL.Server.setActiveUser(AdapterAuthRealm,NULL);
WL.Server.setActiveUser(AdapterAuthRealm的UserIdentity); 返回{
authRequired:假的
};
}
也许,我的code推送通知服务将是非常有用的帮助(角JS):
的console.log(services.service('PushService'));
如果(WL.Client.Push){ WL.Client.Push.onReadyToSubscribe =功能(){ WL.Client.Push.registerEventSourceCallback(
myPush
PushAdapter
PushEventSource
angular.element(document.body的).injector()得到('PushService')pushNotificationReceived)。
}; } services.service('PushService',函数($ Q){ VAR自我=这一点;
self.send =功能(用户ID,文本){
console.info(PushService ::发送,用户ID,文本);
变种推迟= $ q.defer();
如果(typeof运算WL!==未定义){
WL.Client.invokeProcedure({
适配器:PushAdapter',
过程:submitNotification',
参数:用户ID,文字]
},{
的onSuccess:功能(响应){
deferred.resolve(响应);
的console.log(PushService ::推响应:响应);
},
onFailure处:功能(响应){
deferred.reject();
}
});
}其他{
deferred.reject();
console.warn(WL是未定义);
}
返回deferred.promise;
}; self.isSupported =功能(){
VAR则isSupported = FALSE;
如果(WL.Client.Push){
的console.log(WL.Client.Push);
则isSupported = WL.Client.Push.isPushSupported();
}
返回则isSupported;
};
self.isSubscribed =功能(){
VAR isSubscribed = FALSE;
如果(WL.Client.Push){
isSubscribed = WL.Client.Push.isSubscribed('myPush');
}
返回isSubscribed;
};
self.subscribe =功能(){
变种推迟= $ q.defer();
WL.Client.Push.subscribe(myPush,{
的onSuccess:功能(响应){console.info(推::订阅成功); deferred.resolve(响应); },
onFailure处:功能(){console.warn(推::订阅failture); deferred.reject(); }
});
返回deferred.promise;
};
self.unsubscribe =功能(){
变种推迟= $ q.defer();
WL.Client.Push.unsubscribe(myPush,{
的onSuccess:功能(响应){console.info(推::退订成功); deferred.resolve(响应); },
onFailure处:功能(){console.warn(推::退订failture); deferred.reject(); }
});
返回deferred.promise;
};
self.pushNotificationReceived =功能(道具,有效载荷){
console.info(pushNotificationReceived调用::,JSON.stringify(道具),JSON.stringify(负载));
}; 返回自我;
});
有关问题的一种可能的情况是,您要推送到该会话已经结束用户。
例如,如果您有以下情形:
serverSessionTimeout = 3的conf \\服务器\\ worklight.properties(会议将在3分钟内结束)
和应用程序\\\\ COMMON \\ JS \\ initOptions.js
//#多久心跳请求将被发送到服务器工作灯
heartBeatIntervalInSecs:-1,
该移动应用程序将不发送心跳,让你的服务器超时后(会话结束)就像你注销了在服务器端的应用程式。所以,你就成为退订。这可能是在你的推送通知的失败的原因。
一个可能的解决方案是使心跳或增加服务器端的会话超时。
这将是有益的,如果你也可以分享您的配置文件:的conf \\服务器\\ worklight.properties和应用程序\\\\共同\\ JS \\ initOptions.js检查,如果是这种情况。无论如何,如果是这样的情况下,第一PUSH将登录为3分钟,然后经过之后将开始得到的错误。
I'm using Push notification in my Worklight test app. I have made authentication via Worklight Adapter. But in this way, I always receive response from PushAdapter "No subscription found for user:: [sample_username]"
Device is authenticated:
And my test Android device is subscribed for notification.
My simple AuthAdapter:
function onAuthRequired(headers, errorMessage) {
errorMessage = errorMessage ? errorMessage : null;
return {
authRequired: true,
errorMessage: errorMessage
};
}
function submitAuthentication(username, password) {
var userIdentity = {
userId: username,
displayName: username,
attributes: {
foo: "bar"
}
};
WL.Server.setActiveUser("AdapterAuthRealm", null);
WL.Server.setActiveUser("AdapterAuthRealm", userIdentity);
return {
authRequired: false
};
}
Maybe, my code for Push notification service will be useful for help (Angular JS):
console.log(services.service('PushService'));
if (WL.Client.Push){
WL.Client.Push.onReadyToSubscribe = function(){
WL.Client.Push.registerEventSourceCallback(
"myPush",
"PushAdapter",
"PushEventSource",
angular.element(document.body).injector().get('PushService').pushNotificationReceived);
};
}
services.service('PushService', function($q) {
var self = this;
self.send = function(userID, text) {
console.info("PushService:: send ",userID, text);
var deferred = $q.defer();
if (typeof WL !== 'undefined') {
WL.Client.invokeProcedure({
adapter : 'PushAdapter',
procedure : 'submitNotification',
parameters : [userID, text]
},{
onSuccess: function(response) {
deferred.resolve(response);
console.log("PushService:: push response: ",response);
},
onFailure: function(response) {
deferred.reject();
}
});
} else {
deferred.reject();
console.warn("WL is undefined");
}
return deferred.promise;
};
self.isSupported = function() {
var isSupported = false;
if (WL.Client.Push){
console.log(WL.Client.Push);
isSupported = WL.Client.Push.isPushSupported();
}
return isSupported;
};
self.isSubscribed = function() {
var isSubscribed = false;
if (WL.Client.Push){
isSubscribed = WL.Client.Push.isSubscribed('myPush');
}
return isSubscribed;
};
self.subscribe = function() {
var deferred = $q.defer();
WL.Client.Push.subscribe("myPush", {
onSuccess: function(response) { console.info("Push:: subscribe success"); deferred.resolve(response); },
onFailure: function() { console.warn("Push:: subscribe failture"); deferred.reject(); }
});
return deferred.promise;
};
self.unsubscribe = function() {
var deferred = $q.defer();
WL.Client.Push.unsubscribe("myPush", {
onSuccess: function(response) { console.info("Push:: unsubscribe success"); deferred.resolve(response); },
onFailure: function() { console.warn("Push:: unsubscribe failture"); deferred.reject(); }
});
return deferred.promise;
};
self.pushNotificationReceived = function(props, payload) {
console.info("pushNotificationReceived invoked:: ", JSON.stringify(props), JSON.stringify(payload));
};
return self;
});
One possible scenario for your problem is that you are trying to send a push to user that the session had ended. For example, if you have the following scenario:
"serverSessionTimeout=3" at "conf\server\worklight.properties" (Session will be ended in 3 minutes)
And "apps\""\common\js\initOptions.js":
// # How often heartbeat request will be sent to Worklight Server
heartBeatIntervalInSecs: -1,
The mobile app will not send a heartbeat, so after your server timeout(Session will end) is like you were logout out of your app in the server-side. So, you become unsubscribed. This could be the cause of the fail in your push notifications.
A possible solution is to enable the heartbeat or increase the server-side session timeout.
It would be helpful if you could share also your configuration files: conf\server\worklight.properties and "apps\\common\js\initOptions.js" to check if is this the situation. Anyway, if this is the case, the first PUSH will after the login for 3 minutes and then after you would start to get the error.
这篇关于带适配器的认证工作灯推送通知不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!