Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Update method to obtain email for GitHub SSO
Tuan Dang96fbc6c5a0de
diff --git a/backend/src/utils/auth.ts b/backend/src/utils/auth.tsindex f7a1a504ce..3a04639a6a 100644--- a/backend/src/utils/auth.ts+++ b/backend/src/utils/auth.ts@@ -21,8 +21,9 @@ import {} from "../config";import { getSSOConfigHelper } from "../ee/helpers/organizations";import { InternalServerError, OrganizationNotFoundError } from "./errors";-import { ACCEPTED, INVITED, MEMBER } from "../variables";+import { ACCEPTED, INTEGRATION_GITHUB_API_URL, INVITED, MEMBER } from "../variables";import { getSiteURL } from "../config";+import { standardRequest } from "../config/request";// eslint-disable-next-line @typescript-eslint/no-var-requiresconst GoogleStrategy = require("passport-google-oauth20").Strategy;@@ -143,10 +144,28 @@ const initializePassport = async () => {passReqToCallback: true,clientID: clientIdGitHubLogin,clientSecret: clientSecretGitHubLogin,- callbackURL: "/api/v1/sso/github"+ callbackURL: "/api/v1/sso/github",+ scope: ["user:email"]},async (req : express.Request, accessToken : any, refreshToken : any, profile : any, done : any) => {- const email = profile.emails[0].value;+ interface GitHubEmail {+ email: string;+ primary: boolean;+ verified: boolean;+ visibility: null | string;+ }++ const { data }: { data: GitHubEmail[] } = await standardRequest.get(+ `${INTEGRATION_GITHUB_API_URL}/user/emails`,+ {+ headers: {+ Authorization: `Bearer ${accessToken}`+ }+ }+ );++ const primaryEmail = data.filter((gitHubEmail: GitHubEmail) => gitHubEmail.primary)[0];+ const email = primaryEmail.email;let user = await User.findOne({diff --git a/backend/src/variables/integration.ts b/backend/src/variables/integration.tsindex e8bf78b19a..5caa975b2d 100644--- a/backend/src/variables/integration.ts+++ b/backend/src/variables/integration.ts@@ -83,6 +83,7 @@ export const INTEGRATION_BITBUCKET_TOKEN_URL = "https://bitbucket.org/site/oauthexport const INTEGRATION_GCP_API_URL = "https://cloudresourcemanager.googleapis.com";export const INTEGRATION_HEROKU_API_URL = "https://api.heroku.com";export const INTEGRATION_GITLAB_API_URL = "https://gitlab.com/api";+export const INTEGRATION_GITHUB_API_URL = "https://api.github.com";export const INTEGRATION_VERCEL_API_URL = "https://api.vercel.com";export const INTEGRATION_NETLIFY_API_URL = "https://api.netlify.com";export const INTEGRATION_RENDER_API_URL = "https://api.render.com";