Skip to content

Conversation

macintoshhelper
Copy link

@macintoshhelper macintoshhelper commented Aug 3, 2021

Hi, I’m proposing adding a new authorizeAsync function, which helps for people who want to use the WebCrypto APIs, which are synchronous, i.e.

const hmacSha256Base64Digest = async (body, k) => {
  const secret = k;
  const enc = new TextEncoder('utf-8');
  const algorithm = { name: 'HMAC', hash: 'SHA-256' };

  const key = await crypto.subtle.importKey('raw', enc.encode(secret), algorithm, false, ['sign', 'verify']);
  const signature = await crypto.subtle.sign(algorithm.name, key, enc.encode(body));
  const digest = btoa(String.fromCharCode(...new Uint8Array(signature)));

  return digest;
}
 const oauthAuthorized = await oauth.authorizeAsync(request_data, { key: 'asdf', secret: 'qwerty' })

Ref #108

@macintoshhelper
Copy link
Author

macintoshhelper commented Aug 3, 2021

Apologies, just noticed that a PR exists for this already at #83 ; I feel that having both a sync, and async version of the authorize function may be a better approach though and minimise on the lines of code. I can't seem to see the error stack on the CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant