Skip to content

Commit 5a4ae89

Browse files
committed
feat(chrome-extension,shared): Expand WebSSO capabilities. [SDK-836]
1 parent 4b8bedc commit 5a4ae89

19 files changed

+309
-171
lines changed

.changeset/perfect-monkeys-beg.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
'@clerk/chrome-extension': major
3+
'@clerk/shared': patch
4+
---
5+
6+
Expand the ability for `@clerk/chrome-extension` WebSSO to sync with host applications which use URL-based session syncing.
7+
8+
### How to Update
9+
10+
**WebSSO Local Host Permissions:**
11+
12+
Add `*://localhost:*/*` to the `host_permissions` array in your `manifest.json` file:
13+
```json
14+
{
15+
"host_permissions": ["*://localhost:*/*"]
16+
}
17+
```
18+
19+
If you're using a local domain other than `localhost`, you'll want replace that entry with your domain: `*://<DOMAIN>/*`
20+
21+
```json
22+
{
23+
"host_permissions": ["*://<DOMAIN>/*"]
24+
}
25+
```
26+
27+
**WebSSO Provider settings:**
28+
29+
```tsx
30+
<ClerkProvider
31+
publishableKey={publishableKey}
32+
routerPush={to => navigate(to)}
33+
routerReplace={to => navigate(to, { replace: true })}
34+
syncSessionWithTab
35+
36+
// [Development Only]: If the host application isn't on
37+
// `http://localhost`, you can provide it here:
38+
syncSessionHost="http://<DOMAIN>"
39+
>
40+
```

package-lock.json

Lines changed: 43 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/chrome-extension/README.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,34 @@ The 2 supported cases (links to different branches of the same repository):
134134

135135
## WebSSO required settings
136136

137-
### Permissions (in manifest.json)
137+
### Extension Manifest (`manifest.json`)
138138

139-
- "cookies" for more info see (here)[https://developer.chrome.com/docs/extensions/reference/cookies/]
140-
- "storage" for more info see (here)[https://developer.chrome.com/docs/extensions/reference/storage/]
139+
#### Permissions
141140

142-
### Host permissions (in manifest.json)
143-
144-
You will need your Frontend API URL, which can be found in your `Dashboard > API Keys > Advanced > Clerk API URLs`.
141+
You must enable the following permissions in your `manifest.json` file:
145142

146143
```
147-
"host_permissions": ["*://YOUR_CLERK_FRONTEND_API_GOES_HERE/"],
144+
"permissions": ["cookies", "storage"]
148145
```
149146

147+
- For more info on the "cookies" permission: (Google Developer Cookies Reference)[https://developer.chrome.com/docs/extensions/reference/cookies/]
148+
- For more info on the "storage" permission: (Google Developer Storage Reference)[https://developer.chrome.com/docs/extensions/reference/storage/]
149+
150+
#### Host Permissions
151+
152+
You must enable the following host permissions in your `manifest.json` file:
153+
154+
- **Development:** `"host_permissions": ["*://localhost:*/*"]`
155+
- If you're using a domain other than `localhost`, you'll want replace that entry with your domain: `*://<DOMAIN>/*`
156+
- **Production:** `"host_permissions": ["*://<YOUR_CLERK_FRONTEND_API_GOES_HERE>/"]`
157+
- Your Frontend API URL can be found in `Clerk Dashboard > API Keys > Advanced > Clerk API URLs`.
158+
159+
For more info on host permissions: (Google Developer `host_permissions` Reference)[https://developer.chrome.com/docs/extensions/mv3/declare_permissions/#host-permissions]
160+
161+
#### ClerkProvider
162+
163+
If your plan to sync sessions with a host application not on `localhost`, you'll need to use the `syncSessionHost` prop on `ClerkProvider` to specify the domain you're using, inclusive of the protocol. (eg: `https://<domain>`)
164+
150165
<a name="clerk-settings"></a>
151166

152167
### Clerk settings
@@ -160,10 +175,6 @@ curl -X PATCH https://api.clerk.com/v1/instance \
160175
-d '{"allowed_origins": ["chrome-extension://extension_id_goes_here"]}'
161176
```
162177

163-
## Development
164-
165-
The `Enable URL-based session syncing` should be `DISABLED` from the `Clerk Dashboard > Setting` for a development instance to support @clerk/chrome-extension functionality.
166-
167178
## Deploy to Production
168179

169180
Setting the `allowed_origins` (check [Clerk Settings](#clerk-settings)) is **REQUIRED** for both **Development** and **Production** instances when using the WebSSO use case.

packages/chrome-extension/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66

77
roots: ['<rootDir>/src'],
88
testEnvironment: 'jsdom',
9-
setupFilesAfterEnv: ['<rootDir>../../jest.setup-after-env.ts'],
9+
setupFilesAfterEnv: ['<rootDir>../../jest.setup-after-env.ts', '<rootDir>/jest.setup.ts'],
1010

1111
moduleDirectories: ['node_modules', '<rootDir>/src'],
1212
transform: {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
globalThis.chrome = {
2+
cookies: {
3+
// @ts-expect-error - Mock implementation
4+
get: jest.fn(({ url, name }) => `cookies.get:${url}:${name}`),
5+
},
6+
runtime: {
7+
// @ts-expect-error - Mock implementation
8+
getManifest: jest.fn(() => ({
9+
permissions: ['cookies', 'storage'],
10+
host_permissions: ['https://*/*'],
11+
})),
12+
},
13+
storage: {
14+
// @ts-expect-error - Mock implementation
15+
local: {
16+
// @ts-expect-error - Mock implementation
17+
get: jest.fn(async k => Promise.resolve({ [k]: `storage.get:${k}` })),
18+
set: jest.fn(async () => Promise.resolve()),
19+
},
20+
},
21+
};

packages/chrome-extension/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@
4545
"test:coverage": "jest --collectCoverage && open coverage/lcov-report/index.html"
4646
},
4747
"dependencies": {
48-
"@clerk/clerk-js": "5.0.0-alpha-v5.6",
49-
"@clerk/clerk-react": "5.0.0-alpha-v5.6"
48+
"@clerk/clerk-js": "*",
49+
"@clerk/clerk-react": "*",
50+
"@clerk/shared": "*"
5051
},
5152
"devDependencies": {
52-
"@types/chrome": "*",
53+
"@types/chrome": "latest",
5354
"@types/node": "^18.17.0",
5455
"@types/react": "*",
5556
"@types/react-dom": "*",

0 commit comments

Comments
 (0)