-
Notifications
You must be signed in to change notification settings - Fork 21
LuaNode API Documentation
#LuaNode API Documentation #
This document describes the API of the OAuth module when it is used with LuaNode.
Builds a new OAuth client instance.
OAuth:new(consumer_key, consumer_secret, endpoints, [params])
It takes the following parameters:
- consumer_key is the public key
- consumer_secret is the private key
- endpoints is a table containing the URLs where the Service Provider exposes its endpoints. Each endpoint is either a string (its url, the method is POST by default) or a table, with the url in the array part and the method in the 'method' field.
-
params is an optional table with additional parameters:
- field SignatureMethod indicates the signature method used by the server (PLAINTEXT, RSA-SHA1, HMAC-SHA1 (default) )
- field UseAuthHeaders indicates if the server supports oauth_xxx parameters to be sent in the 'Authorization' HTTP header (true by default)
The following methods are meant to be called on a OAuth client instance, like this: client:RequestToken(callback)
.
Requests temporary credentials.
client:RequestToken([arguments, [headers] ], callback)
It takes the following parameters:
- arguments is an optional table with whose keys and values will be encoded as "application/x-www-form-urlencoded" (when doing a POST) or encoded and sent in the query string (when doing a GET).
- headers is an optional table with http headers to be sent in the request
- callback is a mandatory function that will be called when the token is available
Returns nothing. When the token is available or an error occurs, the function callback will be called. It should be a function with the following signature:
function callback(token, status_code, response_headers, status_line, response_body)
Were token is the requested token on success or nil on error plus:
- status_code is the http status code (i.e. 200, 401, etc)
- response_headers is a table with the response headers
- status_line is the http status line as returned from the server (i.e. "200 Ok")
- response_body is a string with the response body
Builds the authorization url that the resource owner must navigate to to grant permission to the client as specified in Resource Owner Authorization
client:BuildAuthorizationUrl([arguments])
- arguments is an optional table with whose keys and values will be encoded as "application/x-www-form-urlencoded" (when doing a POST) or encoded and sent in the query string (when doing a GET).
Returns the fully constructed URL, with both OAuth and custom parameters encoded, and the value of the 'Authorization' header.
Exchanges a request token for an Access token as described here
client:GetAccessToken([arguments[, headers] ], callback)
- arguments is an optional table with whose keys and values will be encoded as "application/x-www-form-urlencoded" (when doing a POST) or encoded and sent in the query string (when doing a GET).
- headers is an optional table with http headers to be sent in the request
- callback is a mandatory function that will be called when the token is available
Returns nothing. When the token is available or an error occurs, the function callback will be called. It should be a function with the following signature:
function callback(token, status_code, response_headers, status_line, response_body)
Were token is the requested token on success or nil on error plus:
- status_code is the http status code (i.e. 200, 401, etc)
- response_headers is a table with the response headers
- status_line is the http status line as returned from the server (i.e. "200 Ok")
- response_body is a string with the response body
After retrieving an access token, this method is used to issue properly authenticated requests.
client:PerformRequest(method, url, [arguments[, headers] ], callback)
- method is the http method (GET, POST, etc)
- url is the url to request
- arguments is an optional table whose keys and values will be encoded as "application/x-www-form-urlencoded" (when doing a POST) or encoded and sent in the query string (when doing a GET). It can also be a string with the body to be sent in the request (usually a POST). In that case, you need to supply a valid Content-Type header.
- headers is an optional table with http headers to be sent in the request
- callback is a mandatory function that will be called when the response is available
Returns nothing. When the response is available (either succesful or with an error), the function callback will be called. It should be a function with the following signature:
function callback(status_code, response_headers, status_line, response_body)
- status_code is the http status code (i.e. 200, 401, etc)
- response_headers is a table with the response headers
- status_line is the http status line as returned from the server (i.e. "200 Ok")
- response_body is a string with the response body
After retrieving an access token, this method is used to build properly authenticated requests but it won't send it. Instead, it will return the needed headers and data that needs to be sent.
client:BuildRequest(method, url, [arguments[, headers] ])
- method is the http method (GET, POST, etc)
- url is the url to request
- arguments is an optional table whose keys and values will be encoded as "application/x-www-form-urlencoded" (when doing a POST) or encoded and sent in the query string (when doing a GET). It can also be a string with the body to be sent in the request (usually a POST). In that case, you need to supply a valid Content-Type header.
- headers is an optional table with http headers to be sent in the request
Returns a table with headers, a table with the (cleaned up) arguments and the request body. So, now you can send the data with whatever network library you have at hand.
Sets or gets the oauth_token OAuth header on a client instance.
old_value = client:GetToken()
client:SetToken(value)
Sets or gets the oauth_token_secret OAuth header on a client instance.
old_value = client:GetTokenSecret()
client:SetTokenSecret(value)
Sets or gets the oauth_verifier OAuth header on a client instance.
old_value = client:GetVerifier()
client:SetVerifier(value)