Here is a detailed guide on how to use iOS Shortcuts to integrate with Vercel API for generating OAuth 1.0a HMAC-SHA1 signatures. The process involves using a backend API to handle signature generation and Shortcuts to send requests, receive the response, and construct the necessary headers for Twitter API requests.
Overall Workflow:
- 
Create a Vercel API:
- This API will handle the signature computation logic and return the timestamp (ts), nonce, and signature required for OAuth 1.0a.
 
- This API will handle the signature computation logic and return the timestamp (
- 
Set up Shortcuts to call the API:
- Use the Shortcuts app to send a request to the Vercel API, retrieve the generated signature, and parse the response.
 
- 
Assemble the Authorization Header:
- Use the returned ts,nonce, andsignatureto construct the OAuth authorization header required for Twitter API calls.
 
- Use the returned 
1. Creating the Vercel API for Signature Generation
Host a Node.js API on Vercel
- Deploy a simple Node.js server on Vercel to handle OAuth 1.0a signature generation.
- The API accepts parameters like the request URL, HTTP method, and body data and uses these inputs to generate a valid OAuth signature.
Steps for Signature Computation
- Parse the incoming request to extract necessary OAuth fields: url,method, and other parameters.
- Use the HMAC-SHA1 algorithm to generate a signature:
- Combine the consumer_secretandaccess_token_secretwith an&separator as the signing key.
- Compute the hash of the base string with this signing key.
 
- Combine the 
- Return a JSON object with:
- 
ts: A timestamp representing the current time.
- 
nonce: A random, unique string to prevent replay attacks.
- 
signature: The computed OAuth signature.
 
- 
Sample Endpoint
- 
URL: https://your-vercel-api-url.com/generate-signature
- Request (POST):
  {
    "url": "https://api.twitter.com/2/tweets",
    "method": "POST",
    "body": "{"text":"Hello, world!"}"
  }
- Response:
  {
    "ts": "1700000000",
    "nonce": "randomString123",
    "signature": "base64EncodedSignatureHere"
  }
2. Setting Up Shortcuts to Call the API
Create a Shortcut
- Open the Shortcuts app on your iOS device and create a new shortcut.
Add the "Get Contents of URL" Action
- Choose the POST method.
- Set the URL to your Vercel API endpoint, e.g., https://your-vercel-api-url.com/generate-signature.
- Add a request body in JSON format to include the necessary parameters:
  {
    "url": "https://api.twitter.com/2/tweets",
    "method": "POST",
    "body": "{"text":"Hello, world!"}"
  }
Process the API Response
- Use the Get Dictionary Value action to extract ts,nonce, andsignaturefrom the API response.
- For example:
- Extract the value for tsand store it in a variableOAuth_Timestamp.
- Extract the value for nonceand store it inOAuth_Nonce.
- Extract the value for signatureand store it inOAuth_Signature.
 
- Extract the value for 
3. Constructing the OAuth Authorization Header
OAuth Header Structure
The header should follow the format:
Authorization: OAuth 
oauth_consumer_key="YOUR_CONSUMER_KEY",
oauth_token="YOUR_ACCESS_TOKEN",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="ts_value",
oauth_nonce="nonce_value",
oauth_version="1.0",
oauth_signature="signature_value"
Combine the Variables
- Use Set Variable actions in Shortcuts to concatenate the extracted values (ts,nonce, andsignature) with other fixed values (e.g., consumer key and token).
- Example:
  Authorization: OAuth 
  oauth_consumer_key="yourConsumerKey",
  oauth_token="yourAccessToken",
  oauth_signature_method="HMAC-SHA1",
  oauth_timestamp=OAuth_Timestamp,
  oauth_nonce=OAuth_Nonce,
  oauth_version="1.0",
  oauth_signature=OAuth_Signature
Pass the Header to Twitter API Request
- Use the constructed header in your request to Twitter's API.
- Add the header in the Request Headers field of the Get Contents of URL action in Shortcuts.
Summary
- 
Vercel API: - Handles complex signature generation logic.
- Returns only the essential values: ts,nonce, andsignature.
 
- 
Shortcuts: - Calls the Vercel API to get the signature data.
- Parses the JSON response to extract required fields.
- Constructs the OAuth Authorization Header dynamically.
- Sends the finalized request with the header to the Twitter API.
 
By offloading the signature generation to Vercel, you simplify the OAuth process in iOS Shortcuts while maintaining flexibility and security. This approach ensures that the Shortcut only handles lightweight tasks like data assembly and API calls.
 

 
    
Top comments (0)