Skip to content

Commit e11fd80

Browse files
authored
Merge pull request #1 from Frameio/bc-pkce
Add PKCE Example
2 parents 2358edb + 4dc3385 commit e11fd80

File tree

4 files changed

+184
-69
lines changed

4 files changed

+184
-69
lines changed

README.md

+22-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
$ npm install
77
```
88

9-
## Usage
9+
## Usage: index.js
1010

11-
Edit the following values in `index.js` to match your OAuth app configuration.
11+
This example demonstrates a basic client using the Authorization Code grant flow.
12+
13+
Edit the following values in `index.js` to match your OAuth App configuration.
1214

1315
- `clientID`
1416
- `clientSecret`
@@ -22,3 +24,21 @@ $ node index.js
2224
```
2325

2426
The application will be available at `http://localhost:5050`.
27+
28+
## Usage: pkce.js
29+
30+
This example demonstrates a basic client using the Authorization Code grant flow with [Proof Key for Code Exchange (PKCE)](https://oauth.net/2/pkce/).
31+
32+
Edit the following values in `index.js` to match your OAuth App configuration.
33+
34+
- `clientID`
35+
- `callbackURL`
36+
- `scopes`
37+
38+
Next, run the application.
39+
40+
```
41+
$ node pkce.js
42+
```
43+
44+
The application will be available at `http://localhost:5050`.

index.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
const express = require('express');
22
const session = require('express-session');
33
const bodyParser = require('body-parser');
4+
45
const app = express();
56
const port = 5050;
67

7-
const clientID = '<CLIENT_ID>';
8-
const clientSecret = '<CLIENT_SECRET>';
9-
const callbackURL = '<CALLBACK_URL>';
10-
const scopes = ['account.read'];
8+
const clientID = '<YOUR-CLIENT-ID>';
9+
const clientSecret = '<YOUR-CLIENT-SECRET>';
10+
const callbackURL = 'http://localhost:5050/callback';
11+
12+
// NOTE: Replace this list of scope strings with whichever you'd like the demo
13+
// app to request consent.
14+
const scopes = 'offline account.read asset.create';
1115

1216
const credentials = {
1317
client: {
@@ -51,6 +55,7 @@ app.get('/callback', async (req, res) => {
5155
const token = oauth2.accessToken.create(result);
5256
return res.status(200).json(token)
5357
} catch (error) {
58+
console.error(error);
5459
return res.status(500).json('Authentication failed');
5560
}
5661
})

package-lock.json

+68-63
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)