Skip to content

Commit 315a4e0

Browse files
committed
feat: allow oauth scope to be configured
1 parent ea523b3 commit 315a4e0

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

library.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ OAuth.loadStrategies = async (strategies) => {
7676
callbackURL,
7777
passReqToCallback: true,
7878
}, async (req, token, secret, { id, displayName, email }, done) => {
79+
if (![id, displayName, email].every(Boolean)) {
80+
return done(new Error('insufficient-scope'));
81+
}
82+
7983
const user = await OAuth.login({
8084
name,
8185
oAuthid: id,
@@ -92,12 +96,12 @@ OAuth.loadStrategies = async (strategies) => {
9296
passport.use(configured[idx].name, strategy);
9397
});
9498

95-
strategies.push(...configured.map(({ name }) => ({
99+
strategies.push(...configured.map(({ name, scope }) => ({
96100
name,
97101
url: `/auth/${name}`,
98102
callbackURL: `/auth/${name}/callback`,
99103
icon: 'fa-check-square',
100-
scope: 'openid email profile',
104+
scope: scope || 'openid email profile',
101105
})));
102106

103107
return strategies;

static/templates/partials/edit-oauth2-strategy.tpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,17 @@
5454
If a relative path is specified here, we will assume the hostname from the authorization URL.
5555
</p>
5656
</div>
57+
58+
<div class="mb-3">
59+
<label class="form-label" for="scope">User Info URL</label>
60+
<input type="text" id="scope" name="scope" title="User Info URL" class="form-control" placeholder="openid email profile" value="{./scope}">
61+
<p class="form-text">
62+
Scopes are used to limit the information returned by the user info URL to only that which is necessary.
63+
Different implementations use different values.
64+
</p>
65+
<p class="form-text">
66+
<strong>Default</strong> &mdash; <code>openid email profile</code>
67+
</p>
68+
</div>
5769
</fieldset>
5870
</form>

0 commit comments

Comments
 (0)