顯示具有 RESTful 標籤的文章。 顯示所有文章
顯示具有 RESTful 標籤的文章。 顯示所有文章

星期一, 4月 14, 2014

REST Authentication

記錄一些Rest Authentication實作

http://stackoverflow.com/questions/319530/restful-authentication 

Here is a truly and completely RESTful authentication solution:

 1. Create a public/private key pair on the authentication server.
 2. Distribute the public key to all servers.
 3. When a client authenticates:
3.1. issue a token which contains the following:
 * Expiration time
 * users name (optional)
 * users IP (optional)
 * hash of a password (optional)
3.2. Encrypt the token with the private key.
3.3. Send the encrypted token back to the user.
4. When the user accesses any API they must also pass in their auth token.
5. Servers can verify that the token is valid by decrypting it using the auth server's public key.

This is stateless/RESTful authentication. Note, that if a password hash were included the user would also send the unencrypted password along with the authentication token. The server could verify that the password matched the password that was used to create the authentication token by comparing hashes. A secure connection using something like HTTPS would be necessary. Javascript on the client side could handle getting the user's password and storing it client side, either in memory or in a cookie, possibly encrypted with the server's public key.

星期二, 1月 31, 2012

星期六, 4月 23, 2011

[JAVA] 快快樂樂學JAVA RESTful Service using Jersey

本文記錄如何在JAVA+TOMCAT下使用Jersey快速建立RESTful WebService :
感謝Owen血尿付出。

第一步:安裝Eclipse跟Tomcat 6.0.32
第二步:下載Jersey Library 1.6。官網http://jersey.java.net/
第三步:將下載的.jar檔放到Tomcat/lib
核心的lib asm-3.1.jar, jersey-core.jar, jersey-server.jar, jsr-311-api-1.0.jar



第四步:開啟Eclipse,新建一個Dynamic Web Project
第五步:修改專案內的YourProjectName/WebContent/WEB-INF/web.xml,新增以下內容

<servlet>
      <servlet-name>JerseyServlet</servlet-name>
      <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
      <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
      <servlet-name>JerseyServlet</servlet-name>
      <url-pattern>/services/*</url-pattern>
 </servlet-mapping>

第六步:第一個HelloWorld Restful API (支援GET / POST)

星期一, 4月 18, 2011

[Alfresco] login using Jquery

/**
 * authentication
 */

$(function(){
 //dologin
 $("#login_submit").click(function(){
  var username = $("#username").val();
  var password = $("#password").val();
  if(username == "" || password == ""){
   alert("Invalid UserName or Password.");
  }else{
   //call resetful api
   
   var endpoint = "http://localhost:8080/alfresco/service/api/login?u=" + username + "&pw=" + password + "&format=json";
   alert(endpoint);
   $.ajax({
     type: "GET",
     headers: {
                 "Content-Type": "application/json"
     },
     url: endpoint,
     //contentType: "application/json",
     processData: false,
     //data: stringData,
     dataType: "jsonp",
     jsonp:"alf_callback",
     jsonpCallback:"jsonp_callback_login",
     statusCode: {
        404: function() {
          alert('page not found');
        },
     400: function() {
           alert('bad request');
         }
     }
   });
  }
 });
});

function jsonp_callback_login(data){
 alert(data.data.ticket);
}

其他你感興趣的文章

Related Posts with Thumbnails