Skip to content

Commit 7d1446d

Browse files
authored
Merge pull request #189 from docusign/feature/pkce-auth
Add PKCE authorization
2 parents d191a0f + 987165d commit 7d1446d

File tree

9 files changed

+2563
-1673
lines changed

9 files changed

+2563
-1673
lines changed

index.js

+391-384
Large diffs are not rendered by default.

jwt_console_project/package-lock.json

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

jwt_console_project/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"author": "DocuSign, Inc",
1313
"license": "ISC",
1414
"dependencies": {
15-
"docusign-esign": "^8.0.0",
15+
"docusign-esign": "^8.0.1",
1616
"fs": "^0.0.1-security",
1717
"fs-extra": "^11.2.0",
1818
"path": "^0.12.7",

lib/DSAuthCodeGrant.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,35 @@ DSAuthCodeGrant.prototype.login = function(req, res, next) {
6060
// Reset
6161
this.internalLogout(req, res);
6262
req.session.authMethod = 'grand-auth';
63-
passport.authenticate('docusign')(req, res, next);
63+
64+
if (req.session?.pkceFailed) {
65+
passport.authenticate('docusign')(req, res, next);
66+
} else {
67+
passport.authenticate('docusign_pkce')(req, res, next);
68+
}
6469
};
6570

6671
DSAuthCodeGrant.prototype.oauth_callback1 = (req, res, next) => {
6772
// This callback URL is used for the login flow
68-
passport.authenticate('docusign', { failureRedirect: '/ds/login' })(req, res, next);
73+
if (req.session?.pkceFailed) {
74+
passport.authenticate('docusign', { failureRedirect: '/ds/login' })(req, res, next);
75+
} else {
76+
passport.authenticate('docusign_pkce', { failureRedirect: '/ds/login' }, (err, user, _info) => {
77+
if (err || !user) { return next(); }
78+
79+
req.logIn(user, function(err) {
80+
if (err) { return next(err); }
81+
return next();
82+
});
83+
})(req, res, next);
84+
}
6985
};
7086
DSAuthCodeGrant.prototype.oauth_callback2 = function _oauth_callback2(req, res, next) {
87+
if (!req.session.pkceFailed && !req?.user?.accessToken) {
88+
req.session.pkceFailed = true;
89+
return res.redirect('/ds/login');
90+
}
91+
7192
this._accessToken = req.user.accessToken;
7293
console.log(`Received access_token: |${req.user.accessToken}|`);
7394
console.log(`Expires at ${req.user.tokenExpirationTimestamp.format('dddd, MMMM Do YYYY, h:mm:ss a')}`);

0 commit comments

Comments
 (0)