Sample code for 30+ languages & platforms
React Native

Generate OAuth 1.0 Signature

Demonstrates how to generate an OAuth 1.0 signature.

Chilkat React Native Downloads

React Native
import { OAuth1 } from '@chilkat/react-native'

function chilkatExample() {
  // This example assumes the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const oauth = new OAuth1();

  // Set input parameters:
  oauth.oauthVersion = '1.0';
  oauth.oauthMethod = 'GET';
  oauth.oauthUrl = 'http://echo.lab.madgex.com/echo.ashx';
  oauth.consumerKey = 'key';
  oauth.consumerSecret = 'secret';
  oauth.token = 'accesskey';
  oauth.tokenSecret = 'accesssecret';
  oauth.nonce = '01020304050607080102030405060708';
  oauth.timestamp = '1441659763';
  // Can be "HMAC-SHA1", "HMAC-SHA256", "RSA-SHA1", or "RSA-SHA2"
  oauth.signatureMethod = 'HMAC-SHA256';

  try {
    oauth.generate();
  } catch {
    console.log(oauth.lastErrorText);
    return;
  }

  // Examine the various outputs:

  console.log(oauth.queryString);
  console.log(oauth.baseString);
  console.log(oauth.hmacKey);
  console.log(oauth.signature);
  console.log(oauth.encodedSignature);
  console.log(oauth.authorizationHeader);
  console.log(oauth.generatedUrl);
}