c0dfa8048a
* feat: BYO Auth Define client-side auth resolvers to be able to supply custom authentication credentials for integrations before a run is performed - Added new defineAuthResolver - Update all integrations to support the new auth resolvers - Strip internal symbols from .d.ts in integrations and trigger-sdk - Added BYO Auth docs - Update Dynamic Schedule to support associated account IDs - Create external accounts just-in-time - Added Account ID field to test job when there are external auth integrations - Show Account ID on run dashboard - Added new Run error state called “Unresolved auth” * Added changeset * Remove @internal from TriggerIntegration public methods * Add void to the result union * DynamicTriggers now work with the new BYO auth system, and added a bunch of docs and docs changes * Add additional key material for registering dynamic trigger task * Add new define* instance methods to the overview
68 lines
1.9 KiB
Plaintext
68 lines
1.9 KiB
Plaintext
---
|
|
title: "defineAuthResolver()"
|
|
description: "Define a custom auth resolver for a specific integration"
|
|
---
|
|
|
|
Auth Resolvers allow you to inject the authentication credentials of **your users**, using a third-party service like [Clerk](https://clerk.com/) or [Nango](https://www.nango.dev/) or your own custom solution.
|
|
|
|
See our [Bring-your-own Auth Guide](/documentation/guides/using-integrations-byo-auth) for more about how this works.
|
|
|
|
<RequestExample>
|
|
|
|
```ts example
|
|
client.defineAuthResolver(slack, async (ctx) => {
|
|
if (!ctx.account?.id) {
|
|
return;
|
|
}
|
|
|
|
const tokens = await clerk.users.getUserOauthAccessToken(ctx.account.id, "oauth_slack");
|
|
|
|
if (tokens.length === 0) {
|
|
throw new Error(`Could not find Slack auth for account ${ctx.account.id}`);
|
|
}
|
|
|
|
return {
|
|
type: "oauth",
|
|
token: tokens[0].token,
|
|
};
|
|
});
|
|
```
|
|
|
|
</RequestExample>
|
|
|
|
## Parameters
|
|
|
|
<ParamField body="integration" type="TriggerIntegration" required>
|
|
The Integration client (e.g. `slack`) to define the auth resolver for.
|
|
</ParamField>
|
|
|
|
<ParamField body="resolver" type="AuthResolver" required>
|
|
The resolver function to use for this integration. Should return a [AuthResolverResult](#authresolverresult) object.
|
|
|
|
{" "}
|
|
|
|
<Expandable title="arguments" defaultOpen>
|
|
<ParamField body="ctx" type="TriggerContext" required>
|
|
The [TriggerContext](/sdk/context) object for the run that is requesting authentication.
|
|
</ParamField>
|
|
<ParamField body="integration" type="TriggerIntegration">
|
|
The Integration client that is requesting authentication.
|
|
</ParamField>
|
|
</Expandable>
|
|
|
|
</ParamField>
|
|
|
|
## AuthResolverResult
|
|
|
|
<ParamField body="type" type="string" required>
|
|
Should be either "apiKey" or "oauth"
|
|
</ParamField>
|
|
|
|
<ParamField body="token" type="string" required>
|
|
The authentication token to use for this integration.
|
|
</ParamField>
|
|
|
|
<ParamField body="additionalFields" type="Record<string, string>">
|
|
Additional fields to pass to the integration.
|
|
</ParamField>
|