简体   繁体   English

Android上的Worklight身份验证问题和isUserAuthenticated

[英]Issue with Worklight authentication on Android and isUserAuthenticated

I am experiencing a problem with authentication within an Android application, I am using Worklight version 5.0.6. 我在Android应用程序中遇到身份验证问题,我正在使用Worklight 5.0.6版。

I have created a secure app using this authentication configuration: 我使用此身份验证配置创建了一个安全的应用:

<securityTests>
    <mobileSecurityTest name="Sencha22-Mobile-SecurityTest">
        <testDeviceId provisioningType="none"/>
        <testUser realm="SampleAppRealm"/>
    </mobileSecurityTest>
</securityTests>

<realms>
    <realm loginModule="StrongDummy" name="SampleAppRealm">
    <className>com.worklight.core.auth.ext.FormBasedAuthenticator</className>
    </realm>
</realms>

<loginModules>
    <loginModule name="StrongDummy">
        <className>com.worklight.core.auth.ext.NonValidatingLoginModule</className>
    </loginModule>
</loginModules>

I also have a ChallengeHandler with the following: 我还有一个ChallengeHandler,其中包括:

challengeHandler.submitLoginFormCallback = function(response) {
var isLoginFormResponse = challengeHandler.isCustomResponse(response);
if(isLoginFormResponse){
    //login unsuccessful
    Ext.Msg.alert('Error', "Login not successful", Ext.emptyFn);
}else{
    //login successful, reload the app
    WL.Client.reloadApp();
}
}

The WL.Client.reloadApp() statement is executing correctly after authentication occurs, however the function: 验证发生后,WL.Client.reloadApp()语句正确执行,但函数:

WL.Client.isUserAuthenticated("SampleAppRealm")

is ALWAYS returning NULL on Android. 总是在Android上返回NULL。

The application works fine when viewed as Common Resources in Chrome. 当在Chrome中作为公共资源查看时,该应用程序正常工作。

Is there a problem with isUserAuthenticated on Android? Android上的isUserAuthenticated存在问题吗?

First of all, I don't think reloading application after authentication is a good idea. 首先,我不认为认证后重新加载应用程序是个好主意。 Now. 现在。 Authentication information is received from WL server once application connects to it. 应用程序连接到WL服务器后,将从WL服务器接收验证信息。 To connect to a WL server you need to either set connectOnStartup:true in initOptions.js or use WL.Client.connect() API. 要连接到WL服务器,您需要在initOptions.js中设置connectOnStartup:true或使用WL.Client.connect()API。 Since you're saying that problem occurs only on android my guess is that you have timing issue. 既然你说这个问题只出现在android上我的猜测是你有时间问题。 Make sure that you're calling isUserAuthenticated API after client has successfully received a response from server. 在客户端成功从服务器收到响应后,请确保您正在调用isUserAuthenticated API。

isUserAuthenticated will always return true or false in 5.0.6 and is completely javascript based (so it should be consistent regardless of platform). isUserAuthenticated将始终在5.0.6中返回true或false,并且完全基于javascript(因此无论平台如何,它都应该是一致的)。 I think something else is going on here to get you a NULL... are there any javascript exceptions? 我认为还有其他东西可以让你获得一个NULL ...有没有javascript例外? One way to check is to use a javascript debugging library on android devices such as weinre (add a javascript file to your html, then connect to a local server to debug console output: http://people.apache.org/~pmuellr/weinre/docs/latest/ ). 一种方法是在Android设备上使用javascript调试库,例如weinre(将javascript文件添加到你的html,然后连接到本地服务器来调试控制台输出: http//people.apache.org/~pmuellr/ weinre / docs / latest / )。 See if there are any exceptions being thrown in the javascript output. 查看javascript输出中是否有任何异常被抛出。 As Anton said, you may also be experiencing a timing issue with your device. 正如Anton所说,您可能还遇到了设备的计时问题。

Side note: Anton is correct: WL.Client.reloadApp() may clear the authentication state based on the device or browser's settings. 附注:Anton正确:WL.Client.reloadApp()可以根据设备或浏览器的设置清除身份验证状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM