Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add authorize async function for asynchronous signature functions #107

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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