Skip to content

[http-client-js] Unbranded Oauth Support #6579

Open
@MaryGao

Description

@MaryGao

Proposal

JavaScript unbranded libraries will provide a flexible interface to support various authentication providers, as shown in the example below. We believe that flexibility + good samples is the right strategy for unbranded JS customers.

For the MVP, our proposal is to expose TokenCredential from the generated client and internally add a Bearer Token pipeline policy. We don’t believe a separate library is needed solely for unbranded identity.


Example: Using Auth0 with Our Libraries (TypeScript)

import { Auth0Client } from "@auth0/auth0-spa-js";
import { TokenCredential, MyClient } from "my-unbranded-lib";

const auth0Client = new Auth0Client({
  domain: "your-auth0-domain",
  clientId: "your-client-id",
  authorizationParams: {
    audience: "your-api-identifier",
  },
});

const auth0Credential: TokenCredential = {
  async getToken(scopes: string | string[], options?: GetTokenOptions) {
    try {
      const token = await auth0Client.getTokenSilently({
        authorizationParams: {
          scope: Array.isArray(scopes) ? scopes.join(" ") : scopes,
        },
      });
      return token ? { token, expiresOnTimestamp: Date.now() + 3600 * 1000 } : null;
    } catch (error) {
      console.error("Failed to retrieve token from Auth0", error);
      return null;
    }
  },
};

const client = new MyClient(auth0Credential);

Looking forward to feedback! 🚀

Metadata

Metadata

Assignees

Labels

1_0_E2Eemitter:client:jsIssue for the JS client emitter: @typespec/http-client-js

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions