<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wikis.tid.es/gvp-public/index.php?action=history&amp;feed=atom&amp;title=Oauth_signature_examples</id>
	<title>Oauth signature examples - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wikis.tid.es/gvp-public/index.php?action=history&amp;feed=atom&amp;title=Oauth_signature_examples"/>
	<link rel="alternate" type="text/html" href="https://wikis.tid.es/gvp-public/index.php?title=Oauth_signature_examples&amp;action=history"/>
	<updated>2026-04-10T08:17:09Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.0</generator>
	<entry>
		<id>https://wikis.tid.es/gvp-public/index.php?title=Oauth_signature_examples&amp;diff=6&amp;oldid=prev</id>
		<title>Id02256: Created page with &quot;This page provides some examples in different languages on how to add OAuth signature to the UNIAPI requests.  It is important to notice that OAuth Signature uses current timesta...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wikis.tid.es/gvp-public/index.php?title=Oauth_signature_examples&amp;diff=6&amp;oldid=prev"/>
		<updated>2014-06-02T08:51:19Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;This page provides some examples in different languages on how to add OAuth signature to the UNIAPI requests.  It is important to notice that OAuth Signature uses current timesta...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This page provides some examples in different languages on how to add OAuth signature to the UNIAPI requests.&lt;br /&gt;
&lt;br /&gt;
It is important to notice that OAuth Signature uses current timestamp for signing the requests. This forces devices to be synchronized with API servers with a small margin allowed. If a device gets an invalid timestamp error (see [[StatusCode]] for more information), it should make use of the [[GetTime]] method, that will return the current server time. This method can be called without OAuth signature to allow devices to sync clocks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Javascript ==&lt;br /&gt;
&lt;br /&gt;
In http://oauth.net/code/ you can find the latest version of oauth.js and sha1.js libraries, used in this code snippet.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
var signedUrl = OAuth.generateOAuthSignedURL(&amp;quot;GET&amp;quot;, url, params, sConsumerKey, sConsumerSecret);&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
generateOAuthSignedURL : function (httpMethod, serviceURL, parameters, consumerKey, consumerSecret) {&lt;br /&gt;
	var timestamp = OAuth.timestamp();&lt;br /&gt;
	var nonce = OAuth.nonce(11);&lt;br /&gt;
	var tokenSecret = &amp;quot;&amp;quot;;&lt;br /&gt;
	var message = null;&lt;br /&gt;
	var accessor = {consumerSecret: consumerSecret, tokenSecret: tokenSecret};&lt;br /&gt;
	var normalizedParameters, signature, resultURL, authorizationHeader;&lt;br /&gt;
&lt;br /&gt;
	//Ponemos este If porque en POST no se mandan los parámetros en las cabeceras HTTP.&lt;br /&gt;
	//Por eso hacemos esta distinción&lt;br /&gt;
	if ((Utils.isArray(parameters) &amp;amp;&amp;amp; parameters.length === 0) || httpMethod === &amp;quot;POST&amp;quot;) {&lt;br /&gt;
		message = { method: httpMethod,&lt;br /&gt;
			action: serviceURL,&lt;br /&gt;
			parameters: OAuth.decodeForm(&amp;#039;&amp;#039;)&lt;br /&gt;
		};&lt;br /&gt;
	}else {&lt;br /&gt;
		message = { method: httpMethod,&lt;br /&gt;
			action: serviceURL,&lt;br /&gt;
			parameters: OAuth.getParameterList(parameters)&lt;br /&gt;
		};&lt;br /&gt;
	}&lt;br /&gt;
	message.parameters.push([&amp;quot;oauth_version&amp;quot;, &amp;quot;1.0&amp;quot;]);&lt;br /&gt;
	message.parameters.push([&amp;quot;oauth_consumer_key&amp;quot;, consumerKey]);&lt;br /&gt;
	//message.parameters.push([&amp;quot;oauth_token&amp;quot;, &amp;quot;&amp;quot;]);&lt;br /&gt;
	message.parameters.push([&amp;quot;oauth_timestamp&amp;quot;, timestamp]);&lt;br /&gt;
	message.parameters.push([&amp;quot;oauth_nonce&amp;quot;, nonce]);&lt;br /&gt;
	message.parameters.push([&amp;quot;oauth_signature_method&amp;quot;, &amp;quot;HMAC-SHA1&amp;quot;]);&lt;br /&gt;
	OAuth.SignatureMethod.sign(message, accessor);&lt;br /&gt;
&lt;br /&gt;
	normalizedParameters = OAuth.SignatureMethod.normalizeParameters(message.parameters);&lt;br /&gt;
	//var signatureBaseString = OAuth.SignatureMethod.getBaseString(message);&lt;br /&gt;
&lt;br /&gt;
	signature = OAuth.percentEncode(OAuth.getParameter(message.parameters, &amp;quot;oauth_signature&amp;quot;));&lt;br /&gt;
	resultURL = serviceURL + &amp;quot;?&amp;quot; + normalizedParameters + &amp;quot;&amp;amp;oauth_signature=&amp;quot; + signature;&lt;br /&gt;
	authorizationHeader = OAuth.getAuthorizationHeader(&amp;quot;&amp;quot;, message.parameters);&lt;br /&gt;
	return resultURL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== C# ==&lt;br /&gt;
&lt;br /&gt;
In http://oauth.net/code/ you can find the latest version of OAuth libraries used in this code snippet.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public void GetRequest(string serviceName, string methodName, Dictionary&amp;lt;string, string&amp;gt; parameters, bool usePost, out string requestMethod, out string requestUrl, out string requestParameters)&lt;br /&gt;
{&lt;br /&gt;
    // Request Method&lt;br /&gt;
    requestMethod = usePost ? &amp;quot;POST&amp;quot; : &amp;quot;GET&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    // Request Url&lt;br /&gt;
    requestUrl = this.serviceRootUrl + &amp;quot;/&amp;quot; + serviceName + &amp;quot;/&amp;quot; + methodName;&lt;br /&gt;
&lt;br /&gt;
    // Request Parameters&lt;br /&gt;
    Dictionary&amp;lt;string, string&amp;gt; requestParameterList = new Dictionary&amp;lt;string, string&amp;gt;(parameters);&lt;br /&gt;
&lt;br /&gt;
    // Consumer key must always be present&lt;br /&gt;
    requestParameterList.Add(&amp;quot;oauth_consumer_key&amp;quot;, this.consumerKey);&lt;br /&gt;
&lt;br /&gt;
    if (this.alwaysSendIpAddress)&lt;br /&gt;
    {&lt;br /&gt;
        if (!requestParameterList.Select(s =&amp;gt; s.Key.ToLower()).Contains(&amp;quot;ipaddress&amp;quot;))&lt;br /&gt;
        {&lt;br /&gt;
            requestParameterList.Add(&amp;quot;ipaddress&amp;quot;, this.GetIpAddress());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    if (this.useSignature)&lt;br /&gt;
    {&lt;br /&gt;
        // Adds signature parameters to the hashtable&lt;br /&gt;
        requestParameterList.Add(&amp;quot;oauth_nonce&amp;quot;, Environment.TickCount.ToString());&lt;br /&gt;
        requestParameterList.Add(&amp;quot;oauth_signature_method&amp;quot;, &amp;quot;HMAC-SHA1&amp;quot;);&lt;br /&gt;
        requestParameterList.Add(&amp;quot;oauth_timestamp&amp;quot;, MibUnixTime.ToUnixTime(DateTime.Now).ToString());&lt;br /&gt;
        requestParameterList.Add(&amp;quot;oauth_version&amp;quot;, &amp;quot;1.0&amp;quot;);&lt;br /&gt;
        requestParameterList.Add(&amp;quot;oauth_signature&amp;quot;, new OAuthSigner(this.consumerSecret).GenerateSignature(new OAuthRequest(requestUrl.ToString(), requestParameterList, requestMethod)));&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Request data&lt;br /&gt;
    List&amp;lt;string&amp;gt; items = new List&amp;lt;string&amp;gt;();&lt;br /&gt;
    foreach (KeyValuePair&amp;lt;string, string&amp;gt; kvp in requestParameterList)&lt;br /&gt;
    {&lt;br /&gt;
        items.Add(string.Concat(kvp.Key, &amp;quot;=&amp;quot;, System.Web.HttpUtility.UrlEncode(kvp.Value)));&lt;br /&gt;
    }&lt;br /&gt;
    requestParameters = string.Join(&amp;quot;&amp;amp;&amp;quot;, items.ToArray());&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Id02256</name></author>
		
	</entry>
</feed>