Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda