0 worklight-security worklight-adapters ibm-mobilefirst
我正在使用WorkLight 5.0.6开发移动应用程序,我想在适配器返回的响应中附加一个安全cookie.
我们没有使用WorkLight身份验证领域,因为我们不希望将会话"绑定"到群集生产环境中的特定WL服务器.我们通过调用登录适配器对会话进行身份验证,该适配器根据后端系统对用户详细信息进行身份验证.作为来自登录适配器调用的响应的一部分,我想创建一个包含经过身份验证的信息的安全cookie(仅限http),并将其附加到从登录适配器返回的响应中.cookie也应该包含在从应用程序调用服务器的后续Adapter中.
问候,
Tom.
Run Code Online (Sandbox Code Playgroud)
我建议尝试创建一个与后端通信的自定义Worklight身份验证器.可以在此处找到自定义验证器的文档:
要回答您的问题,以下是我在不使用自定义验证器的情况下接近它的方法:
function authenticate(用户名,密码){
Run Code Online (Sandbox Code Playgroud)var invocationData = { adapter : 'authenticationAdapter', procedure : 'authenticate', parameters : [username, password] }; WL.Client.invokeProcedure(invocationData, { onSuccess : authSuccess, onFailure : authFailure });}
Run Code Online (Sandbox Code Playgroud)function authSuccess(response){ console.log("Auth Success"); var myCookie = response.invocationResult.responseHeaders.CookieName // Save cookie somehow }
function adapterRequestForProtectedResource(){
var mySecureCookie = getMyCookieFromLocalStorage();
Run Code Online (Sandbox Code Playgroud)var invocationData = { adapter : 'protectedResourceAdapter', procedure : 'getResource', parameters : [mySecureCookie] }; WL.Client.invokeProcedure(invocationData, { onSuccess : success, onFailure : failure });}
在适配器上,在标头中设置cookie
function getResource(secureCookie){
// Secure cookie must be of the form: "CookieName=cookievalue"
var input = {
method : 'get',
returnedContentType : 'json',
path : "/resource",
headers: {"Cookie": secureCookie}
};
return WL.Server.invokeHttp(input);
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
2175 次 |
| 最近记录: |