microsoft / microsoft/typespec
[http-client-js] Unbranded Oauth Support
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
## **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)**
```ts
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! 🚀
Contributor guide
Assessment
This issue has not been assessed yet.