http://www.zorba-xquery.com/modules/oauth/client

View as XML or JSON.

This module provides the functions necessary to acquire access to the personal resources of a user through the open standard called OAuth. The application/mashup creator does not need to know the specifics of OAuth to use this module.

Function Summary

access-token ($service-provider as schema-element(sp:service-provider), $parameters as schema-element(p:parameters)) as schema-element(p:parameters)

This function allows the client to obtain a set of token credentials from the service provider by making an authenticated HTTP request to the Token Request endpoint.

add-parameter ($parameters as schema-element(p:parameters)?, $name as xs:string, $value as xs:string) as schema-element(p:parameters)

Adds an OAuth parameter to an OAuth Parameters instance.

parameter ($params as schema-element(p:parameters), $string as xs:string) as xs:string

This function returns the string value of the parameters whose key matches a $string input.

parameters ($name as xs:string, $value as xs:string) as element(p:parameters)

Create an OAuth Parameters instance.

protected-resource ($protected-resource as schema-element(http:request), $service-provider as schema-element(sp:service-provider), $parameters as schema-element(p:parameters)) as item()*

This function allows the client access to the protected resources of the user.

request-token ($service-provider as schema-element(sp:service-provider)) as schema-element(p:parameters)

This function allows the client to obtain a set of temporary credentials from the service provider by making an authenticated HTTP request to the Temporary Credential Request endpoint.

request-token ($service-provider as schema-element(sp:service-provider), $parameters as schema-element(p:parameters)?) as schema-element(p:parameters)

This function allows the client to obtain a set of temporary credentials from the service provider by making an authenticated HTTP request to the Temporary Credential Request endpoint.

service-provider ($consumer-key as xs:string, $consumer-secret as xs:string, $signature-method as xs:string, $realm as xs:string, $authorize-url as xs:string, $request-token-method as xs:string, $request-token-url as xs:string, $request-token-callback-url as xs:string, $access-token-method as xs:string, $access-token-url as xs:string) as schema-element(sp:service-provider)

Utility function to build a service provider object.

Functions

access-token#2

declare  %an:sequential function oauth:access-token($service-provider as schema-element(sp:service-provider), $parameters as schema-element(p:parameters)) as schema-element(p:parameters)
This function allows the client to obtain a set of token credentials from the service provider by making an authenticated HTTP request to the Token Request endpoint. This function is provided for convenience.

Parameters

service-provider as schema-element(sp:service-provider)
Contains service provider information
parameters as schema-element(p:parameters)
parameters

Returns

schema-element(p:parameters)
token credentials correctly parsed as parameter elements, or an error if http response status is not 200 OK
 let $service-provider := oauth:service-provider(...) let $parameters := oauth:parameters("oauth_token", "#") let $parameters := oauth:add-parameter($parameters, "oauth_token_secret", "#") let $tokens := oauth:access-token($service-provider, $parameters) ... 

add-parameter#3

declare  function oauth:add-parameter($parameters as schema-element(p:parameters)?, $name as xs:string, $value as xs:string) as schema-element(p:parameters)
Adds an OAuth parameter to an OAuth Parameters instance. Instances of OAuth parameters are used to contain value/pair data such as oauth_token and oauth_token_secret. For instance the following code snippet:
  let $params := oauth:parameters("oauth_token", "#")
  let $params := oauth:add-parameter($params, "oauth_token_secret", "#")
  return $params
 
Returns the following XML schema instance:
 
   
   
 
 

Parameters

parameters as schema-element(p:parameters)
parameters
name as xs:string
parameter name
value as xs:string
parameter value

Returns

schema-element(p:parameters)
instance of the OAuth parameters XML schema.

parameter#2

declare  function oauth:parameter($params as schema-element(p:parameters), $string as xs:string) as xs:string
This function returns the string value of the parameters whose key matches a $string input.

Parameters

params as schema-element(p:parameters)
element parameters
string as xs:string
string as the "key" name

Returns

xs:string
string value of the parameter with key $string
 let $params := oauth:parameters("oauth_token", "token") let $params := oauth:add-parameter($params, "oauth_token_secret", "secret") let $token-secret := oauth:parameter($params, "oauth_token_secret") return $token-secret 

parameters#2

declare  function oauth:parameters($name as xs:string, $value as xs:string) as element(p:parameters)
Create an OAuth Parameters instance. Instances of OAuth parameters are used to contain value/pair data such as oauth_token and oauth_token_secret. For instance the following code snippet:
  oauth:parameters("oauth_token", "#")
 
Returns the following XML schema instance:
 
   
 
 

Parameters

name as xs:string
parameter name
value as xs:string
parameter value

Returns

element(p:parameters)
instance of the OAuth parameters XML schema.

protected-resource#3

declare  %an:sequential function oauth:protected-resource($protected-resource as schema-element(http:request), $service-provider as schema-element(sp:service-provider), $parameters as schema-element(p:parameters)) as item()*
This function allows the client access to the protected resources of the user. This function is provided for convenience.

Parameters

protected-resource as schema-element(http:request)
(Not schema-validated) http:request element with http method and href.
service-provider as schema-element(sp:service-provider)
Information about the service provider
parameters as schema-element(p:parameters)
parameters

Returns

item()*
protected resources parsed as parameter elements, or an error if http response status is not 200 OK
 let $tokens := oauth:parameters("oauth_token", "#") let $tokens := oauth:add-parameter($tokens, "oauth_token_secret", "#") let $service-provider := oauth:service-provider(...) let $request := validate {  } return oauth:protected-resource($request, $service-provider, $tokens) 

request-token#1

declare  %an:sequential function oauth:request-token($service-provider as schema-element(sp:service-provider)) as schema-element(p:parameters)
This function allows the client to obtain a set of temporary credentials from the service provider by making an authenticated HTTP request to the Temporary Credential Request endpoint. This function is provided for convenience for request-token#2. Invoking this function is equivalent to:
 oauth:request-token($service-provider, ())
 

Parameters

service-provider as schema-element(sp:service-provider)
Information about the service provider

Returns

schema-element(p:parameters)
temporary credentials correctly parsed as parameter elements, or an error if http response status is not 200 OK

request-token#2

declare  %an:sequential function oauth:request-token($service-provider as schema-element(sp:service-provider), $parameters as schema-element(p:parameters)?) as schema-element(p:parameters)
This function allows the client to obtain a set of temporary credentials from the service provider by making an authenticated HTTP request to the Temporary Credential Request endpoint. This function is provided for convenience.

Parameters

service-provider as schema-element(sp:service-provider)
Information about the service provider
parameters as schema-element(p:parameters)
Additionnal parameters to the request

Returns

schema-element(p:parameters)
temporary credentials correctly parsed as parameter elements, or an error if http response status is not 200 OK
 let $twitter-config := oauth:service-provider(...) let $additional-parameter := oauth:parameters("foo", "bar") let $tokens := oauth:request-token($twitter-config, $additional-parameter) let $token := oauth:parameter($tokens, "oauth_token") let $token-secret := oauth:parameter($tokens, "oauth_token_secret") ... 

service-provider#10

declare  function oauth:service-provider($consumer-key as xs:string, $consumer-secret as xs:string, $signature-method as xs:string, $realm as xs:string, $authorize-url as xs:string, $request-token-method as xs:string, $request-token-url as xs:string, $request-token-callback-url as xs:string, $access-token-method as xs:string, $access-token-url as xs:string) as schema-element(sp:service-provider)
Utility function to build a service provider object. This object contains the information required by the OAuth client to interact with an OAuth service provider. For instance the following expression:
 let $consumer-key     := "#"
 let $consumer-secret  := "#"
 let $signature-method := "HMAC-SHA1"
 let $realm            := "twitter.com"
 let $authorize-url    := "http://api.twitter.com/oauth/authorize"
 let $request-token-method := "POST"
 let $request-token-url := "https://twitter.com/oauth/request_token"
 let $request-token-callback-url := "https://twitter.com/oauth/request_token"
 let $access-token-method := "POST"
 let $access-token-url := "https://api.twitter.com/oauth/access_token"
 return oauth:service-provider(
   $consumer-key, $consumer-secret, $signature-method,
   $realm, $authorize-url, $request-token-method,
   $request-token-url, $request-token-callback-url,
   $access-token-method, $access-token-url
 )
 
Will return the following XML schema instance:
 
   
   
 
 

Parameters

consumer-key as xs:string
Client Identifier, also known as the consumer-key
consumer-secret as xs:string
Client Shared-Secret, also known as the consumer-secret
signature-method as xs:string
Method with which the signing key is signed (typically HMAC-SHA1)
realm as xs:string
Realm that defines the protection space
authorize-url as xs:string
authorize-url
request-token-method as xs:string
request-token-method
request-token-url as xs:string
request-token-url
request-token-callback-url as xs:string
request-token-callback-url
access-token-method as xs:string
access-token-method
access-token-url as xs:string
access-token-url

Returns

schema-element(sp:service-provider)
instance of the OAuth service provider XML schema.