Skip to content

Commit b407745

Browse files
baoduySteven Hoang
andauthored
add Azure AD authentication (sqlpad#1040)
* add Azure AD authentication * add SQLPAD_OIDC_SCOPE variable for OIDC allows to customise the authentication scope and LowerCase email before compare * fixed checkAllowedDomains issue when comparing email address * revert gitignore, settings and package-lock.json files * revert package-lock of client and server Co-authored-by: Steven Hoang <[email protected]>
1 parent 6186770 commit b407745

6 files changed

Lines changed: 19 additions & 3 deletions

File tree

docs/authentication.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ SQLPAD_OIDC_LINK_HTML = "Sign in with OpenID"
133133

134134
SQLPAD_OIDC_CLIENT_ID = "actual-client-id"
135135
SQLPAD_OIDC_CLIENT_SECRET = "actual-client-secret"
136+
137+
# Authentication scope allows to customize the scope depend on the supported provider.
138+
# Default value is "openid profile email roles"
139+
SQLPAD_OIDC_SCOPE = "openid profile email roles"
140+
136141
# Issuer endpoint (will vary by provider)
137142
# As of version 6.4.0 the issuer endpoint is the only URL needed
138143
# as long as the OIDC provider supplies .well-known endpoints

server/auth-strategies/oidc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ async function enableOidc(config) {
9090
{
9191
passReqToCallback: true,
9292
client,
93-
params: { scope: 'openid profile email roles' },
93+
params: {
94+
scope: config.get('oidcScope') || 'openid profile email roles',
95+
},
9496
},
9597
openidClientHandler
9698
)

server/config.dev.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ SQLPAD_CONNECTIONS__devdbdriverid123__filename = "./test/fixtures/sales.sqlite"
2121
# SQLPAD_OIDC_CLIENT_ID = CLIENT_ID
2222
# SQLPAD_OIDC_CLIENT_SECRET = SECRET
2323
# SQLPAD_OIDC_ISSUER = "https://dev-350224.okta.com/oauth2/default"
24+
# SQLPAD_OIDC_SCOPE = "openid profile email roles"
2425
# If below are provided, the old passport-openidconnect implementation is used
2526
# If the below are NOT provided, the new openid-client implementation is used
2627
# SQLPAD_OIDC_AUTHORIZATION_URL = "https://dev-350224.okta.com/oauth2/default/v1/authorize"

server/lib/check-allowed-domains.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
*/
1818
module.exports = function checkAllowedDomains(allowedDomains, email) {
1919
if (allowedDomains) {
20-
const domain = email.split('@').pop();
21-
const domains = allowedDomains.split(' ').map((domain) => domain.trim());
20+
const domain = email.split('@').pop().toLowerCase();
21+
const domains = allowedDomains
22+
.split(' ')
23+
.map((domain) => domain.trim().toLowerCase());
2224

2325
return domains.includes(domain);
2426
}

server/lib/config/config-items.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ const configItems = [
358358
envVar: 'SQLPAD_OIDC_LINK_HTML',
359359
default: 'Sign in with OpenID',
360360
},
361+
{
362+
key: 'oidcScope',
363+
envVar: 'SQLPAD_OIDC_SCOPE',
364+
default: 'openid profile email roles',
365+
},
361366
{
362367
key: 'webhookEnabled',
363368
envVar: 'SQLPAD_WEBHOOK_ENABLED',

server/routes/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const wrap = require('../lib/wrap');
99
*/
1010
async function getApp(req, res) {
1111
const { config } = req;
12+
1213
const currentUser =
1314
req.isAuthenticated() && req.user
1415
? {

0 commit comments

Comments
 (0)