forked from danny-avila/LibreChat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes: danny-avila#3438 TODO: - write config Doc
- Loading branch information
1 parent
8b31f25
commit 94ea18a
Showing
20 changed files
with
173 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const socialLogin = require('./socialLogin'); | ||
const { Strategy: AppleStrategy } = require('passport-apple'); | ||
const { logger } = require('~/config'); | ||
const jwt = require('jsonwebtoken'); | ||
|
||
/** | ||
* Extract profile details from the decoded idToken | ||
* @param {Object} params - Parameters from the verify callback | ||
* @param {string} params.idToken - The ID token received from Apple | ||
* @param {Object} params.profile - The profile object (may contain partial info) | ||
* @returns {Object} - The extracted user profile details | ||
*/ | ||
const getProfileDetails = ({ idToken, profile }) => { | ||
if (!idToken) { | ||
logger.error('idToken is missing'); | ||
throw new Error('idToken is missing'); | ||
} | ||
|
||
const decoded = jwt.decode(idToken); | ||
|
||
logger.debug( | ||
`Decoded Apple JWT: ${JSON.stringify(decoded, null, 2)}`, | ||
); | ||
|
||
return { | ||
email: decoded.email, | ||
id: decoded.sub, | ||
avatarUrl: null, // Apple does not provide an avatar URL | ||
username: decoded.email | ||
? decoded.email.split('@')[0].toLowerCase() | ||
: `user_${decoded.sub}`, | ||
name: decoded.name | ||
? `${decoded.name.firstName} ${decoded.name.lastName}` | ||
: profile.displayName || null, | ||
emailVerified: true, // Apple verifies the email | ||
}; | ||
}; | ||
|
||
// Initialize the social login handler for Apple | ||
const appleLogin = socialLogin('apple', getProfileDetails); | ||
|
||
module.exports = () => | ||
new AppleStrategy( | ||
{ | ||
clientID: process.env.APPLE_CLIENT_ID, | ||
teamID: process.env.APPLE_TEAM_ID, | ||
callbackURL: `${process.env.DOMAIN_SERVER}${process.env.APPLE_CALLBACK_URL}`, | ||
keyID: process.env.APPLE_KEY_ID, | ||
privateKeyLocation: process.env.APPLE_PRIVATE_KEY_PATH, | ||
passReqToCallback: false, // Set to true if you need to access the request in the callback | ||
}, | ||
appleLogin, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
|
||
export default function AppleIcon() { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
xmlSpace="preserve" | ||
viewBox="0 0 814 1000" | ||
id="apple" | ||
className="h-6 w-6" | ||
> | ||
<path | ||
d="M788.1 340.9c-5.8 4.5-108.2 62.2-108.2 190.5 0 148.4 130.3 200.9 134.2 202.2-.6 3.2-20.7 71.9-68.7 141.9-42.8 61.6-87.5 123.1-155.5 123.1s-85.5-39.5-164-39.5c-76.5 0-103.7 40.8-165.9 40.8s-105.6-57-155.5-127C46.7 790.7 0 663 0 541.8c0-194.4 126.4-297.5 250.8-297.5 66.1 0 121.2 43.4 162.7 43.4 39.5 0 101.1-46 176.3-46 28.5 0 130.9 2.6 198.3 99.2zm-234-181.5c31.1-36.9 53.1-88.1 53.1-139.3 0-7.1-.6-14.3-1.9-20.1-50.6 1.9-110.8 33.7-147.1 75.8-28.5 32.4-55.1 83.6-55.1 135.5 0 7.8 1.3 15.6 1.9 18.1 3.2.6 8.4 1.3 13.6 1.3 45.4 0 102.5-30.4 135.5-71.3z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters