Skip to content

Commit

Permalink
fix: make sure AUTH_DISABLE_NEW_USERS is respected when using oauth (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop authored Oct 11, 2024
1 parent 58dc724 commit bbb97d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/routes/oauth/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export const PROVIDERS_CONFIG: Record<
client_id: process.env.AUTH_PROVIDER_AZUREAD_CLIENT_ID,
client_secret: process.env.AUTH_PROVIDER_AZUREAD_CLIENT_SECRET,
authorize_url: `${azureBaseUrl}/[subdomain]/oauth2/authorize`,
custom_params: {
prompt: 'select_account',
},
access_url: `${azureBaseUrl}/[subdomain]/oauth2/token`,
profile_url: `${azureBaseUrl}/[subdomain]/openid/userinfo`,
subdomain: process.env.AUTH_PROVIDER_AZUREAD_TENANT || 'common',
Expand Down
5 changes: 5 additions & 0 deletions src/routes/oauth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export const oauthProviders = Router()
const userInput = await transformOauthProfile(profile, options);
user = await insertUser({
...userInput,
disabled: ENV.AUTH_DISABLE_NEW_USERS,
userProviders: {
data: [
{
Expand All @@ -349,6 +350,10 @@ export const oauthProviders = Router()
}

if (user) {
if (user.disabled) {
return sendError(res, 'disabled-user', { redirectTo }, true);
}

const { refreshToken } = await getNewRefreshToken(user.id);
// * redirect back user to app url
return res.redirect(generateRedirectUrl(redirectTo, { refreshToken }));
Expand Down

0 comments on commit bbb97d4

Please sign in to comment.