taskcluster / taskcluster-client-web

A Taskcluster client library for the browser
Mozilla Public License 2.0
3 stars 8 forks source link

Allow automatic credential fetch from access token #1

Closed eliperelman closed 6 years ago

eliperelman commented 6 years ago

This would allow you to do:

import { Auth } from 'taskcluster-client-web';

const accessToken = 'get access token';
const auth = new Auth({ accessToken });

auth.currentScopes().then(({ scopes }) => /* do whatever */);

So now every client will await the fetching of credentials if an accessToken is provided.

eliperelman commented 6 years ago

Also note that you can override what URL you choose to fetch credentials from, as well as the underlying mechanism for fetching those credentials:

new Client({
  exchangeAccessTokenUrl: String,

  exchangeAccessToken: Function<String accessToken, String exchangeAccessTokenUrl> ->
    Promise<Object<credentials, expires>>
});

For example:

new Client({
  exchangeAccessTokenUrl:
    'https://taskcluster-login.ngrok.io/v1/oidc-credentials/mozilla-auth0',

  // or ignore completely, not even making a request
  exchangeAccessToken: (accessToken, url) =>
    Promise.resolve({ credentials: {}, expires: new Date() })
});
eliperelman commented 6 years ago

@djmitche ready for review again.