-
Notifications
You must be signed in to change notification settings - Fork 350
feat(backend): Add OAuth Application endpoints to Backend API client #5599
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5322bff
feat(backend): Add OAuth Applications to Backend API client
tmilewski 3fe73a0
Merge branch 'main' into tm/eco-587-oauth-applications
tmilewski 29c0820
fix: Formatting issues introduced by GH editor
tmilewski df230d2
fix: Make sure casing is consistent
tmilewski 4addf40
fix: Make sure casing is consistent
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,19 @@ | ||
--- | ||
'@clerk/backend': minor | ||
--- | ||
|
||
Adds the ability to perform CRUD operations on OAuth Applications to the Backend API client. | ||
|
||
|
||
```ts | ||
import { createClerkClient } from '@clerk/backend'; | ||
|
||
const clerkClient = createClerkClient(...); | ||
|
||
await clerkClient.oauthApplications.list({...}); | ||
await clerkClient.oauthApplications.get('templateId'); | ||
await clerkClient.oauthApplications.create({...}); | ||
await clerkClient.oauthApplications.update({...}); | ||
await clerkClient.oauthApplications.delete('templateId'); | ||
await clerkClient.oauthApplications.rotateSecret('templateId'); | ||
``` |
94 changes: 94 additions & 0 deletions
94
packages/backend/src/api/endpoints/OauthApplicationsApi.ts
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,94 @@ | ||
import type { ClerkPaginationRequest } from '@clerk/types'; | ||
|
||
import { joinPaths } from '../../util/path'; | ||
import type { DeletedObject } from '../resources'; | ||
import type { PaginatedResourceResponse } from '../resources/Deserializer'; | ||
import type { OauthApplication } from '../resources/OauthApplication'; | ||
import { AbstractAPI } from './AbstractApi'; | ||
|
||
const basePath = '/oauth_applications'; | ||
|
||
type CreateOAuthApplicationParams = { | ||
/** | ||
* The name of the new OAuth application. | ||
* | ||
* @remarks Max length: 256 | ||
*/ | ||
name: string; | ||
/** | ||
* An array of redirect URIs of the new OAuth application | ||
*/ | ||
redirectUris?: Array<string> | null | undefined; | ||
/** | ||
* Define the allowed scopes for the new OAuth applications that dictate the user payload of the OAuth user info endpoint. Available scopes are `profile`, `email`, `public_metadata`, `private_metadata`. Provide the requested scopes as a string, separated by spaces. | ||
*/ | ||
scopes?: string | null | undefined; | ||
/** | ||
* If true, this client is public and you can use the Proof Key of Code Exchange (PKCE) flow. | ||
*/ | ||
public?: boolean | null | undefined; | ||
}; | ||
|
||
type UpdateOAuthApplicationParams = CreateOAuthApplicationParams & { | ||
/** | ||
* The ID of the OAuth application to update | ||
*/ | ||
oauthApplicationId: string; | ||
}; | ||
|
||
export class OAuthApplicationsApi extends AbstractAPI { | ||
public async list(params: ClerkPaginationRequest = {}) { | ||
return this.request<PaginatedResourceResponse<OauthApplication[]>>({ | ||
method: 'GET', | ||
path: basePath, | ||
queryParams: params, | ||
}); | ||
} | ||
|
||
public async get(oauthApplicationId: string) { | ||
this.requireId(oauthApplicationId); | ||
|
||
return this.request<OauthApplication>({ | ||
method: 'GET', | ||
path: joinPaths(basePath, oauthApplicationId), | ||
}); | ||
} | ||
|
||
public async create(params: CreateOAuthApplicationParams) { | ||
return this.request<OauthApplication>({ | ||
method: 'POST', | ||
path: basePath, | ||
bodyParams: params, | ||
}); | ||
} | ||
|
||
public async update(params: UpdateOAuthApplicationParams) { | ||
const { oauthApplicationId, ...bodyParams } = params; | ||
|
||
this.requireId(oauthApplicationId); | ||
|
||
return this.request<OauthApplication>({ | ||
method: 'PATCH', | ||
path: joinPaths(basePath, oauthApplicationId), | ||
bodyParams, | ||
}); | ||
} | ||
|
||
public async delete(oauthApplicationId: string) { | ||
this.requireId(oauthApplicationId); | ||
|
||
return this.request<DeletedObject>({ | ||
method: 'DELETE', | ||
path: joinPaths(basePath, oauthApplicationId), | ||
}); | ||
} | ||
|
||
public async rotateSecret(oauthApplicationId: string) { | ||
this.requireId(oauthApplicationId); | ||
|
||
return this.request<OauthApplication>({ | ||
method: 'POST', | ||
path: joinPaths(basePath, oauthApplicationId, 'rotate_secret'), | ||
}); | ||
} | ||
} |
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
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,41 @@ | ||
import type { OauthApplicationJSON } from './JSON'; | ||
|
||
export class OauthApplication { | ||
constructor( | ||
readonly id: string, | ||
readonly instanceId: string, | ||
readonly name: string, | ||
readonly clientId: string, | ||
readonly isPublic: boolean, // NOTE: `public` is reserved | ||
readonly scopes: string, | ||
readonly redirectUris: Array<string>, | ||
readonly authorizeUrl: string, | ||
readonly tokenFetchUrl: string, | ||
readonly userInfoUrl: string, | ||
readonly discoveryUrl: string, | ||
readonly tokenIntrospectionUrl: string, | ||
readonly createdAt: number, | ||
readonly updatedAt: number, | ||
readonly clientSecret?: string, | ||
) {} | ||
|
||
static fromJSON(data: OauthApplicationJSON) { | ||
return new OauthApplication( | ||
data.id, | ||
data.instance_id, | ||
data.name, | ||
data.client_id, | ||
data.public, | ||
data.scopes, | ||
data.redirect_uris, | ||
data.authorize_url, | ||
data.token_fetch_url, | ||
data.user_info_url, | ||
data.discovery_url, | ||
data.token_introspection_url, | ||
data.created_at, | ||
data.updated_at, | ||
data.client_secret, | ||
); | ||
} | ||
} |
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
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.