Skip to content

Commit b578225

Browse files
feat(clerk-js): Add OAuthConsent component (#6021)
1 parent 4f93634 commit b578225

File tree

20 files changed

+577
-6
lines changed

20 files changed

+577
-6
lines changed

.changeset/six-crabs-carry.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/clerk-react': patch
4+
'@clerk/types': patch
5+
---
6+
7+
Introduce internal `<OAuthConsent />` component to be used internally in the machine auth OAuth flow in account portal.

packages/clerk-js/bundlewatch.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{ "path": "./dist/clerk.browser.js", "maxSize": "69KB" },
55
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "113KB" },
66
{ "path": "./dist/clerk.headless*.js", "maxSize": "52KB" },
7-
{ "path": "./dist/ui-common*.js", "maxSize": "106KB" },
7+
{ "path": "./dist/ui-common*.js", "maxSize": "106.1KB" },
88
{ "path": "./dist/vendors*.js", "maxSize": "39.8KB" },
99
{ "path": "./dist/coinbase*.js", "maxSize": "38KB" },
1010
{ "path": "./dist/createorganization*.js", "maxSize": "5KB" },

packages/clerk-js/sandbox/app.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const AVAILABLE_COMPONENTS = [
3333
'organizationSwitcher',
3434
'waitlist',
3535
'pricingTable',
36+
'oauthConsent',
3637
] as const;
3738

3839
const COMPONENT_PROPS_NAMESPACE = 'clerk-js-sandbox';
@@ -91,6 +92,7 @@ const componentControls: Record<(typeof AVAILABLE_COMPONENTS)[number], Component
9192
organizationSwitcher: buildComponentControls('organizationSwitcher'),
9293
waitlist: buildComponentControls('waitlist'),
9394
pricingTable: buildComponentControls('pricingTable'),
95+
oauthConsent: buildComponentControls('oauthConsent'),
9496
};
9597

9698
declare global {
@@ -310,6 +312,21 @@ void (async () => {
310312
'/pricing-table': () => {
311313
Clerk.mountPricingTable(app, componentControls.pricingTable.getProps() ?? {});
312314
},
315+
'/oauth-consent': () => {
316+
const searchParams = new URLSearchParams(window.location.search);
317+
const scopes = (searchParams.get('scopes')?.split(',') ?? []).map(scope => ({
318+
scope,
319+
description: `Grants access to your ${scope}`,
320+
}));
321+
Clerk.__internal_mountOAuthConsent(
322+
app,
323+
componentControls.oauthConsent.getProps() ?? {
324+
scopes,
325+
oAuthApplicationName: searchParams.get('oauth-application-name'),
326+
redirectUrl: searchParams.get('redirect_uri'),
327+
},
328+
);
329+
},
313330
'/open-sign-in': () => {
314331
mountOpenSignInButton(app, componentControls.signIn.getProps() ?? {});
315332
},

packages/clerk-js/sandbox/template.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@
260260
PricingTable
261261
</a>
262262
</li>
263+
<li class="relative">
264+
<a
265+
class="relative isolate flex w-full rounded-md border border-white px-2 py-[0.4375rem] text-sm hover:bg-gray-50 aria-[current]:bg-gray-50"
266+
href="/oauth-consent"
267+
>
268+
OAuthConsent
269+
</a>
270+
</li>
263271
<li class="relative">
264272
<a
265273
class="relative isolate flex w-full rounded-md border border-white px-2 py-[0.4375rem] text-sm hover:bg-gray-50 aria-[current]:bg-gray-50"

packages/clerk-js/src/core/clerk.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { allSettled, handleValueOrFn, noop } from '@clerk/shared/utils';
1717
import type {
1818
__internal_CheckoutProps,
1919
__internal_ComponentNavigationContext,
20+
__internal_OAuthConsentProps,
2021
__internal_PlanDetailsProps,
2122
__internal_UserVerificationModalProps,
2223
AuthenticateWithCoinbaseWalletParams,
@@ -1037,6 +1038,23 @@ export class Clerk implements ClerkInterface {
10371038
);
10381039
};
10391040

1041+
public __internal_mountOAuthConsent = (node: HTMLDivElement, props?: __internal_OAuthConsentProps) => {
1042+
this.assertComponentsReady(this.#componentControls);
1043+
void this.#componentControls.ensureMounted({ preloadHint: 'OAuthConsent' }).then(controls =>
1044+
controls.mountComponent({
1045+
name: 'OAuthConsent',
1046+
appearanceKey: '__internal_oauthConsent',
1047+
node,
1048+
props,
1049+
}),
1050+
);
1051+
};
1052+
1053+
public __internal_unmountOAuthConsent = (node: HTMLDivElement) => {
1054+
this.assertComponentsReady(this.#componentControls);
1055+
void this.#componentControls.ensureMounted().then(controls => controls.unmountComponent({ node }));
1056+
};
1057+
10401058
/**
10411059
* `setActive` can be used to set the active session and/or organization.
10421060
*/

0 commit comments

Comments
 (0)