Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
titleEngine Compatibility

This library has not yet been ported to the New Pico Engine


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.

...

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

Namespace

string

Code Block
language
languageJavaScript
themeConfluenceJavaScript
needs_auth = oauthmodule:has_token("some_auth_provider");

...

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

 


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

...

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

Code Block
languageJavaScript
themeConfluencelanguageJavaScript
pre {
  myParams = {
    'include_entities' : 'true',
    'include_rts' : 'true',
    'screen_name' : "kynetx_test",
    'count' : 2
  };
  myTokens = {
    'access_token' : '100844323-sldflsdfoopsdfop',
    'access_token_secret' : 'ksdfoiso9foisdfoksdfoij'
  };
}
oauthmodule:get('twitter') 
  with
        url = 'https://api.twitter.com/1.1/statuses/user_timeline.json' and
        params = myParams and 
        access_tokens = myTokens;

...

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

Code Block
languageJavaScript
themeConfluencelanguageJavaScript
result = oauthmodule:get('twitter', {
  'url' : 'https://api.twitter.com/1.1/statuses/user_timeline.json',
  'params' : {
    'include_entities' : 'true',
    'include_rts' : 'true',
    'screen_name' : "kynetx_test",
    'count' : 2
  },
  'access_tokens' : {
    'access_token' : '100844323-sldflsdfoopsdfop',
    'access_token_secret' : 'ksdfoiso9foisdfoksdfoij'
  }} );

...

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

Code Block
languageJavaScript
themeConfluence
languageJavaScript
auth_url_defaults = oauthmodule:get_auth_url('twitter');

explicit_oauth_url = oauthmodule:get_auth_url('v1.0a',{
  'request_token_url' => 'https://api.twitter.com/oauth/request_token',
  'authorization_url' => 'https://api.twitter.com/oauth/authorize',
  'access_token_url' => 'https://api.twitter.com/oauth/access_token'
};

...


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

Code Block
languageJavaScript
themeConfluence
languageJavaScript
google_auth_url = oauthmodule:get_auth_url('google',{
  'params' : {
    'scope' : 'https://www.google.com/m8/feeds/'
   }
} );

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

Code Block
language
languageJavaScript
themeConfluenceJavaScript
secure_auth_url = oauthmodule:get_auth_url('twitter',{
  'use_https' : 1
});

...

Raise a blue event

Code Block
languageJavaScript
themeConfluencelanguageJavaScript
google_auth_url = oauthmodule:get_auth_url('google',{
  'raise_callback_event' => 'RCA',
  'app_id'=>'a144x123'} );

Redirect to a specific page

Code Block
languageJavaScript
themeConfluencelanguageJavaScript
google_auth_url = oauthmodule:get_auth_url('google',{
  'type' => 'redirect',
  'url' => 'http://www.windley.com/'} );