From 7c8a930061f5dcf6b416ca9706bda86a1a49254a Mon Sep 17 00:00:00 2001 From: Ruben Talstra Date: Mon, 3 Feb 2025 21:30:02 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20added=20Github=20Enterprise?= =?UTF-8?q?=20SSO=20login=20(#5621)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * https://github.com/danny-avila/LibreChat/issues/2812 * refactored the code to simplify it. * removed unneeded code * removed unneeded code --- .env.example | 3 +++ api/server/socialLogins.js | 2 +- api/strategies/githubStrategy.js | 9 +++++++++ api/strategies/index.js | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 93408df7bb..d87021ea4b 100644 --- a/.env.example +++ b/.env.example @@ -389,6 +389,9 @@ FACEBOOK_CALLBACK_URL=/oauth/facebook/callback GITHUB_CLIENT_ID= GITHUB_CLIENT_SECRET= GITHUB_CALLBACK_URL=/oauth/github/callback +# GitHub Eenterprise +# GITHUB_ENTERPRISE_BASE_URL= +# GITHUB_ENTERPRISE_USER_AGENT= # Google GOOGLE_CLIENT_ID= diff --git a/api/server/socialLogins.js b/api/server/socialLogins.js index ec3a73e0ac..f39d1da596 100644 --- a/api/server/socialLogins.js +++ b/api/server/socialLogins.js @@ -64,4 +64,4 @@ const configureSocialLogins = (app) => { } }; -module.exports = configureSocialLogins; +module.exports = configureSocialLogins; \ No newline at end of file diff --git a/api/strategies/githubStrategy.js b/api/strategies/githubStrategy.js index bb3712eeba..1c3937381e 100644 --- a/api/strategies/githubStrategy.js +++ b/api/strategies/githubStrategy.js @@ -20,6 +20,15 @@ module.exports = () => callbackURL: `${process.env.DOMAIN_SERVER}${process.env.GITHUB_CALLBACK_URL}`, proxy: false, scope: ['user:email'], + ...(process.env.GITHUB_ENTERPRISE_BASE_URL && { + authorizationURL: `${process.env.GITHUB_ENTERPRISE_BASE_URL}/login/oauth/authorize`, + tokenURL: `${process.env.GITHUB_ENTERPRISE_BASE_URL}/login/oauth/access_token`, + userProfileURL: `${process.env.GITHUB_ENTERPRISE_BASE_URL}/api/v3/user`, + userEmailURL: `${process.env.GITHUB_ENTERPRISE_BASE_URL}/api/v3/user/emails`, + ...(process.env.GITHUB_ENTERPRISE_USER_AGENT && { + userAgent: process.env.GITHUB_ENTERPRISE_USER_AGENT, + }), + }), }, githubLogin, ); diff --git a/api/strategies/index.js b/api/strategies/index.js index cac8460914..242984beaf 100644 --- a/api/strategies/index.js +++ b/api/strategies/index.js @@ -18,4 +18,4 @@ module.exports = { facebookLogin, setupOpenId, ldapLogin, -}; +}; \ No newline at end of file