This site has been deprecated. Do not edit pages here. Please visit the new Pico Labs documentation.


Skip to end of metadata
Go to start of metadata

 

OAuthModule is primarily a module to facilitate communications with external APIs that use OAuth 1.0a. Phil Windley has demonstrated an implementation of OAuth 1.0a in pure KRL.

Common Parameters

namespace

<namespace> generally refers to the <keyname> defined in the META block with the key keyword.  It is possible to dynamically bind OAuth tokens to a <namespace> so you can associate multiple tokens to an OAuth 1.0a provider; ie: "twitter_dev" and "twitter_user"

Predicates

has_token

Returns 1 if the user has an OAuth 1.0a token associated with <namespace>

Namespace

string

Just because an account has an auth token does not mean that it is still valid or hasn't been revoked or timed out.  This is a convenience function so you don't have to make a protected resource request to determine if this is a new account.

Actions

The oauthmodule provides the following familiar HTTP methods as protected resource requests; ie: the request will provide the proper request signature and tokens for OAuth requests.

  • post
  • put
  • get
  • head
  • delete
  • patch

 

oauthmodule:<method>(<namespace>) with
  url = <url> and
  headers = <map> and
  params = <map> and
  body = <string> and
  response_headers = <array> and
  access_tokens = <map>;

url : the base url for the protected resource request; ie: for twitter ("https://api.twitter.com/1.1/statuses/user_timeline.json")

headers : some APIs require specific information passed in a header or require that the OAuth information is passed in the header; ie: for google ('GData-Version' : 2.0)

params : additional information required by the source API

ie: for twitter's user_timeline

'params' : {
            'include_entities' : 'true',
            'include_rts' : 'true',
            'screen_name' : "kynetx_test",
            'count' : 2
        }

body : where the particular HTTP method specifies that parameters are sent in the body, provide a properly encoded string; ie: form-multipart

req_body = <<
{
    "data" : {
        "title" : "Appointment title",
        "details" : "Meeting like a boss",
        "transparency" : "opaque",
        "status" : "confirmed",
        "location" : "San Peete, UT",
        "when" : [
            {
                "start" : "2012-06-12T19:07:32Z",
                "end"   : "2012-06-12T20:07:32Z"
            }
        ]
    }
}
>>;

response_headers : Some services will return a redirect.  In that case, rather than try to parse the response content, you can request the 'Location' response header be included in the result

access_tokens : This value will pre-empt any values that might have been defined in the META block.  This can be useful if you would like to make a request with your developer credentials rather than the user tokens, or if you have user tokens from an alternative source

Here is an example of a complete request to the Twitter v1.1 API that uses access_tokens to provide OAuth authentication

Functions

The oauthmodule provides the following familiar HTTP methods as protected resource requests; ie: the request will provide the proper request signature and tokens for OAuth requests.

  • post
  • put
  • get
  • head
  • delete
  • patch

The format is just like the comparable actions, but, instead of passing parameters using the modifier syntax, you place the parameters in a hash/map as the second argument

get_auth_url

The authorization url is the url that the developer presents to the user to initiate the OAuth 1.0a dance.  For Twitter and Google, the OAuth urls are well known so you can skip providing the OAuth URLs by using 'twitter' or 'google' as your namespace.  In other cases, as a developer, you need to provide the 3 URLs specified by the OAuth protocol

 

Google added the concept of 'scope' to their implementation of OAuth 1.0a, so a get_auth_url request for Google access to the Calendar API would look like

You can force the authorization url to use HTTPS (for the callback) by specifying

You can also modify the behavior of KRL when the OAuth provider redirects the user to the KRL callback

Draft Specification

These options were created before the SKY eventing system was introduced.  The implementation is likely to change if we update the functionality to be compatible with sky.

Raise a blue event

Redirect to a specific page

Labels: