Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
Interacting with Oauth1 API in cloudflare worker (Flickr)

I'm needing to interact with the Flickr api from a cloudflare worker, but it's turning out to be exceedingly tricky.

My initial idea was to reach for the oauth1.0a library, but unfortunately it requires being passed a synchronous signature function. This is an issue because I need to use WebCrypto on the worker and it only exposes an asynchronous API.

Are there any other libraries I can use? I've currently spent hours trying to manually craft the request but keep getting errors saying the signature is bad.

This is my current attempt using someone's fork of oauth1.0a that adds support for an async signature function. This currently results in an "invalid_signature" response:

import OAuth from 'oauth-1.0a';

const CALLBACK_URL = "https://localhost:3000/oauth/callback";

const encoder = new TextEncoder();

async function signData(baseString: string, keyString: string) {
  return await crypto.subtle.importKey(
    'raw',
    encoder.encode(keyString),
    { name: 'HMAC', hash: 'SHA-1' },
    false,
    ['sign']
  ).then(key => {
    return crypto.subtle.sign(
      "HMAC",
      key,
      encoder.encode(baseString)
    );
  }).then(signature => {
    let b = new Uint8Array(signature);
    // base64 digest
    return btoa(String.fromCharCode(...b));
  });
}

export async function getRequestToken(consumerKey: string, consumerSecret: string) {
  const url = "https://www.flickr.com/services/oauth/request_token";
  const token = {
    key: consumerKey,
    secret: consumerSecret
  }
  const oauth = new OAuth({
    consumer: token,
    signature_method: 'HMAC-SHA1',
    // @ts-ignore
    hash_function: signData,
  });
  const requestData = {
    url,
    method: 'GET',
    data: {
      oauth_callback: CALLBACK_URL
    }
  };

  // @ts-ignore
  const authorisedRequest = await oauth.authorizeAsync(requestData, token);
  let params = new URLSearchParams();
  for (let [key, value] of Object.entries(authorisedRequest)) {
    params.append(key, value as string);
  }
  const response = await fetch(requestData.url + `?${params}`, {
    method: requestData.method,
  });

  const body = await response.text();
  const parsedBody = oauth.deParam(body);
  return parsedBody;
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!