Skip to content

Commit 342dd44

Browse files
authored
Merge pull request #13 from descope-sample-apps/auth_code
Update sample app to use authorization code flow instead of device authentication
2 parents 7d54812 + 5cdc6d7 commit 342dd44

13 files changed

Lines changed: 1969 additions & 320 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
node_modules/
33
dist/
44
.vscode/
5-
.DS_Store
5+
.DS_Store
6+
.env.local

README.md

Lines changed: 26 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,17 @@
1-
# Descope Chrome Extension Sample
1+
# Descope Chrome Extension Sample App
22

33
[![License: ISC](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
44
[![Node.js Version](https://img.shields.io/badge/Node.js-16%2B-green.svg)](https://nodejs.org/)
55
[![Chrome Extension](https://img.shields.io/badge/Chrome-Extension-yellow.svg)](https://developer.chrome.com/docs/extensions/)
66
[![Manifest V3](https://img.shields.io/badge/Manifest-V3-orange.svg)](https://developer.chrome.com/docs/extensions/mv3/)
77

8-
A production-ready Chrome extension sample demonstrating secure device authentication using [Descope](https://www.descope.com/). This extension showcases how to integrate Descope's authentication platform within a browser extension context using modern Chrome Extension Manifest V3 standards.
9-
10-
https://github.com/user-attachments/assets/1511921b-440b-4f90-954a-bd261f6ac730
11-
12-
8+
A Chrome extension sample app demonstrating secure OAuth 2.0 authorization code flow using [Descope Federated Apps](https://www.descope.com/). This extension showcases how to integrate Descope's authentication platform within a browser extension context using modern Chrome Extension Manifest V3 standards.
139

1410
## Features
1511

16-
- 🔐 **Device Authentication Flow** - Secure device-based authentication using Descope
12+
- 🔐 **OAuth 2.0 Authorization Code Flow** - Secure OIDC authentication using Descope Federated Apps
1713
- 🚀 **Manifest V3 Compliant** - Built with the latest Chrome Extension standards
18-
- 📱 **Cross-Device Support** - Works seamlessly across different devices
19-
20-
## Table of Contents
21-
22-
- [Getting Started](#getting-started)
23-
- [Installation](#installation)
24-
- [Configuration](#configuration)
25-
- [Development](#development)
26-
- [Usage](#usage)
27-
- [Scripts](#scripts)
28-
- [License](#license)
14+
- 🎯 **PKCE Security** - Implements Proof Key for Code Exchange for enhanced security
2915

3016
## Getting Started
3117

@@ -55,26 +41,21 @@ Before you begin, ensure you have the following installed:
5541

5642
## Configuration
5743

58-
### 1. Descope Project Setup
44+
### 1. Descope Setup
5945

6046
1. **Create a Descope Project:**
6147
- Go to the [Descope Console](https://app.descope.com/)
6248
- Create a new project or select an existing one
63-
- Note your **Project ID** and **Project URL**
49+
- Note your **Project ID**
6450

65-
2. **Configure Authentication Methods:**
66-
- Navigate to Authentication Methods in your Descope console
67-
- Enable desired authentication methods (Email, SMS, Social, etc.)
68-
- Configure device trust settings if needed
51+
2. **Configure Federated App:**
52+
- Navigate to Federated Apps in your Descope console
53+
- Use the OIDC default application or create a new OIDC Federated App
54+
- Note your **App ID** (optional - defaults to OIDC default application)
6955

7056
### 2. Extension Configuration
7157

72-
The extension requires your Descope project details:
73-
74-
- **Project ID**: Your Descope project identifier
75-
- **Issuer Domain**: Your Descope project domain (e.g., `https://auth.company.com`)
76-
77-
These can be configured through the extension popup interface after installation.
58+
Enter your **Project ID** and optionally your **App ID** in the extension popup after installation. If no App ID is provided, the extension will use the default Descope OIDC app.
7859

7960
## Development
8061

@@ -83,108 +64,41 @@ These can be configured through the extension popup interface after installation
8364
For active development with hot reload:
8465

8566
```bash
86-
npm run watch
67+
npm run watch # Build and watch for changes
8768
```
8869

89-
This command:
90-
- Uses Rollup to bundle JavaScript and CSS
91-
- Outputs files to the `dist/` directory
92-
- Watches for file changes and rebuilds automatically
93-
- Enables live development workflow
94-
95-
### Loading the Extension in Chrome
70+
### Loading in Chrome
9671

97-
1. **Open Chrome Extensions page:**
98-
- Navigate to `chrome://extensions/`
99-
- Or use Chrome menu → More tools → Extensions
100-
101-
2. **Enable Developer Mode:**
102-
- Toggle the "Developer mode" switch in the top right corner
103-
104-
3. **Load the Extension:**
105-
- Click "Load unpacked"
106-
- Select the `dist/` directory from this project
107-
- The extension icon will appear in your Chrome toolbar
108-
109-
4. **Reload After Changes:**
110-
- Click the reload icon on your extension card in `chrome://extensions/`
111-
- Or use the keyboard shortcut `Ctrl+R` (Windows/Linux) or `Cmd+R` (Mac)
112-
113-
### Development Tips
114-
115-
- **Debug Console**: Right-click the extension icon → Inspect popup
116-
- **Background Script Debugging**: Go to `chrome://extensions/` → Click "Service worker" under your extension
117-
- **Hot Reload**: Changes to source files automatically trigger rebuilds when using `npm run watch`
72+
1. Go to `chrome://extensions/`
73+
2. Enable "Developer mode"
74+
3. Click "Load unpacked" and select the `dist/` directory
11875

11976
## Usage
12077

121-
### First Time Setup
78+
### Setup
12279

12380
1. **Click the Extension Icon:**
12481
- Look for the Descope icon in your Chrome toolbar
12582
- Click to open the authentication popup
12683

12784
2. **Enter Project Details:**
128-
- **Issuer Domain**: Enter your Descope project URL
129-
- **Client ID**: Enter your Descope project ID
85+
- **Project ID**: Enter your Descope project ID (required)
86+
- **App ID**: Enter your Descope Federated App ID (optional - defaults to OIDC default application)
13087

13188
3. **Initiate Authentication:**
13289
- Click the "Login" button
133-
- The device authentication flow will begin
90+
- The OAuth authorization code flow will begin
13491

13592
### Authentication Flow
13693

137-
1. **Device Code Generation:**
138-
- Extension generates a unique device code
139-
- QR code or verification URL is displayed
140-
141-
2. **Complete Authentication:**
142-
- Follow the displayed instructions
143-
- Verify your identity on the Descope verification page
144-
- Return to the extension popup
145-
146-
3. **Success State:**
147-
- User information will be displayed
148-
- Authentication tokens are securely stored
149-
- Extension is ready for use
150-
94+
1. **Authorization Request**: Extension generates a code verifier/challenge and redirects to Descope
95+
2. **User Authentication**: User authenticates through the Descope flow
96+
3. **Code Exchange**: Extension exchanges authorization code for tokens using PKCE
97+
4. **Token Storage**: Access and ID tokens are securely stored and are able to be used by the extension
15198

15299
## Scripts
153100

154101
| Command | Description |
155102
|---------|-------------|
156-
| `npm run build` | Build the extension for production |
157-
| `npm run watch` | Build and watch for changes during development |
158-
| `npm test` | Run tests (currently not implemented) |
159-
160-
### Production Build
161-
162-
For creating a production-ready build:
163-
164-
```bash
165-
npm run build
166-
```
167-
168-
This creates optimized files in the `dist/` directory ready for Chrome Web Store submission.
169-
170-
### Getting Help
171-
172-
If you encounter issues:
173-
174-
1. Check the [Issues](https://github.com/descope-sample-apps/chrome-extension/issues) page
175-
2. Review [Descope Documentation](https://docs.descope.com/)
176-
3. Contact [Descope Support](https://www.descope.com/support)
177-
178-
## License
179-
180-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
181-
182-
## Support
183-
184-
- **Documentation**: [Descope Docs](https://docs.descope.com/)
185-
- **Community**: [Descope Community](https://community.descope.com/)
186-
- **Support**: [Contact Support](https://www.descope.com/support)
187-
188-
---
189-
190-
Made with ❤️ by the Descope team
103+
| `npm run build` | Build for production |
104+
| `npm run watch` | Build and watch for changes |

package-lock.json

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,5 @@
2121
"rollup-plugin-delete": "^3.0.1",
2222
"rollup-plugin-postcss": "^4.0.2"
2323
},
24-
"dependencies": {
25-
"@descope/web-component": "3.43.20",
26-
"@descope/web-components-ui": "1.115.0"
27-
}
24+
"dependencies": {}
2825
}

public/manifest.json

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "Descope Extension",
3-
"description": "Descope Flow Extension",
2+
"name": "Descope Federated App Extension",
3+
"description": "Descope OIDC Federated App Chrome Extension",
44
"version": "1.0",
55
"manifest_version": 3,
66
"action": {
@@ -10,13 +10,20 @@
1010
"background": {
1111
"service_worker": "background.js"
1212
},
13+
"permissions": [
14+
"identity",
15+
"storage",
16+
"activeTab",
17+
"webNavigation"
18+
],
1319
"host_permissions": [
14-
"https://static.descope.com/*"
20+
"https://*.descope.com/*",
21+
"https://*.descope.io/*"
1522
],
1623
"web_accessible_resources": [
17-
{
18-
"resources": ["config.json", "theme.json"],
19-
"matches": ["<all_urls>"]
20-
}
21-
]
24+
{
25+
"resources": ["descope.png"],
26+
"matches": ["<all_urls>"]
27+
}
28+
]
2229
}

0 commit comments

Comments
 (0)