-
Notifications
You must be signed in to change notification settings - Fork 435
feat(backend): Add agent tokens endpoints #7783
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
Open
tmilewski
wants to merge
5
commits into
main
Choose a base branch
from
tom/user-4622-implement-utt-backend-sdk-endpoints
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1fcb8ac
feat(backend): Add test session tokens endpoints
tmilewski 28ec9d6
chore: Add JSDoc
tmilewski 2291c84
chore: Add redirectUrl
tmilewski f03d40c
chore: Rename Test Session -> Agent
tmilewski f76dbf1
fix: Re-add testing-token export
tmilewski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/backend': minor | ||
| --- | ||
|
|
||
| Add support for Agent Tokens API endpoint which allows developers to create agent tokens that can be used to impersonate users through automated flows. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type { AgentToken } from '../resources/AgentToken'; | ||
| import { AbstractAPI } from './AbstractApi'; | ||
|
|
||
| type CreateAgentTokenParams = { | ||
| /** | ||
| * The ID of the user to create an agent token for. | ||
| */ | ||
| userId: string; | ||
| /** | ||
| * The maximum duration that the session which will be created by the generated agent token should last. | ||
| * By default, the duration is 30 minutes. | ||
| */ | ||
| sessionMaxDurationInSeconds?: number; | ||
| /** | ||
| * The URL to redirect to after the agent token is consumed. | ||
| */ | ||
| redirectUrl?: string; | ||
| }; | ||
|
|
||
| const basePath = '/agent_tokens'; | ||
|
|
||
| export class AgentTokenAPI extends AbstractAPI { | ||
| /** | ||
| * @experimental This is an experimental API for the Agent Tokens feature that is available under a private beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. | ||
| */ | ||
| public async create(params: CreateAgentTokenParams) { | ||
| return this.request<AgentToken>({ | ||
| method: 'POST', | ||
| path: basePath, | ||
| bodyParams: params, | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import type { AgentTokenJSON } from './JSON'; | ||
|
|
||
| /** | ||
| * Represents a agent token resource. | ||
| * | ||
| * Agent tokens are used for testing purposes and allow creating sessions | ||
| * for users without requiring full authentication flows. | ||
| */ | ||
| export class AgentToken { | ||
| constructor( | ||
| /** | ||
| * The unique identifier for the agent token. | ||
| */ | ||
| readonly id: string, | ||
| /** | ||
| * The unique identifier for the user associated with this token. | ||
| */ | ||
| readonly userId: string, | ||
| /** | ||
| * The agent token string value. | ||
| */ | ||
| readonly token: string, | ||
| /** | ||
| * The current status of the token: 'pending', 'accepted', or 'revoked'. | ||
| */ | ||
| readonly status: 'pending' | 'accepted' | 'revoked', | ||
| /** | ||
| * The URL associated with the agent token. | ||
| */ | ||
| readonly url: string, | ||
| /** | ||
| * Unix timestamp (in milliseconds) indicating when the token was created. | ||
| */ | ||
| readonly createdAt: number, | ||
| /** | ||
| * Unix timestamp (in milliseconds) indicating when the token was last updated. | ||
| */ | ||
| readonly updatedAt: number, | ||
| ) {} | ||
|
|
||
| /** | ||
| * Creates a AgentToken instance from a JSON object. | ||
| * | ||
| * @param data - The JSON object containing agent token data | ||
| * @returns A new AgentToken instance | ||
| */ | ||
| static fromJSON(data: AgentTokenJSON): AgentToken { | ||
| return new AgentToken(data.id, data.user_id, data.token, data.status, data.url, data.created_at, data.updated_at); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.