0

我有一个问题,我需要从登录 Web 服务获取 SSO 令牌,但我似乎无法获取它。当我发布 ajax 帖子时,它会返回登录网页的 html 代码。我试图搜索 stackoverflow 和谷歌的提示,但我什么也没得到。这是带有 web 服务的 java 函数文件,可以使用 url 调用,出于安全原因,我无法在此处发布。有人可以给我一个提示或更好的例子吗?

    package lv.rtu.itd.mobile.api.v1.service;



    public interface SecurityService {

    /**
     * Try to login and aquire SSO token.
     * 
     * @param username - attribute identifying person. This might me UID, email, short UID, or other supported
     *            attribues.
     * @param password - password of the user.
     * @return SSO token identifying user's session or <code>null</code> in case of invalid credentials.
     */
    String login(String username, String password);

    /**
     * Checks if there's a SSO session that can be identified by provided token.
     * 
     * @param token - token of SSO session returned by {@link #login(String, String)};
     * @return <code>true</code> if SSO session is valid, <code>false</code> otherwise.
     */
    boolean isTokenValid(String token);

    /**
     * Tries to log out the user's SSO session with given token.
     * 
     * @param token - token identifying user's SSO session.
     */
    void logout(String token);
}
4

1 回答 1

0

您的问题包含的细节太少。首先,可以给出示例 AJAX 代码。

假设JSON-RPC是选择的协议,以下应该可以工作:

POST https://your.domain.com/api/SecurityServiceURL
Content-Type: application/json
{"jsonrpc": "2.0", "method": "login", "params": {"username":"yourusername","password":"yourpassword"}, "id": 1}

在 JQuery AJAX 中,应该看起来像(未测试):

$.ajax({
  url: 'https://your.domain.com/api/SecurityServiceURL', 
      data: JSON.stringify ({"jsonrpc": "2.0", "method": "login", "params": {"username":"yourusername","password":"yourpassword"}, "id": 1}),  
      type:"POST",
      contentType:"application/json",
      success: function (data) { 
             alert("ok");
      },
      error: function (err) {
             alert("err");
      }
   });
于 2013-07-17T08:35:11.583 回答