ThirdAuth is a simple TypeScript library to securely validate third-party authentication with Apple, Google, X (Twitter), SnapChat and LinkedIn.
- Supports multiple Apple, LinkedIn, X (Twitter), SnapChat and Google Sign-In handlers
- Manages different accounts with client IDs
- Periodically updates Apple client secrets
npm install third-auth
Register an Apple Sign-In handler:
ThirdAuth.registerHandler({
clientId: 'config.apple.clientId',
clientSecret: 'config.apple.clientSecret',
keyId: 'config.apple.keyId',
teamId: 'config.apple.teamId',
privateKey: 'config.apple.privateKey',
}, ThirdPartyType.Apple);
Register a X (Twitter) Sign-In handler:
ThirdAuth.registerHandler({
clientId: 'config.x.clientId',
clientSecret: 'config.x.clientSecret',
redirectURI: 'config.x.redirectURI',
}, ThirdPartyType.X);
Register a LinkedIn Sign-In handler:
ThirdAuth.registerHandler({
clientId: 'config.linkedIn.clientId',
clientSecret: 'config.linkedIn.clientSecret',
redirectURI: 'config.linkedIn.redirectURI',
}, ThirdPartyType.LinkedIn);
Register a SnapChat Sign-In handler:
ThirdAuth.registerHandler({
clientId: 'config.snapChat.clientId',
clientSecret: 'config.snapChat.clientSecret',
redirectURI: 'config.snapChat.redirectURI',
}, ThirdPartyType.SnapChat);
Register a Google Sign-In handler:
ThirdAuth.registerHandler({
clientId: 'config.google.clientId',
clientSecret: 'config.google.clientSecret',
}, ThirdPartyType.Google);
Validate an Apple authorization code:
const payload = await ThirdAuth
.getAppleHandler('config.apple.clientId')
.validateUserCredentials({ authorizationCode: loginDto.authorizationCode });
Validate a X (Twitter) authorization code:
const payload = await ThirdAuth
.getXHandler('config.x.clientId')
.validateUserCredentials({ authorizationCode: loginDto.authorizationCode });
Validate a LinkedIn authorization code:
const payload = await ThirdAuth
.getLinkedInHandler('config.linkedIn.clientId')
.validateUserCredentials({ authorizationCode: loginDto.authorizationCode });
Validate a SnapChat authorization code:
const payload = await ThirdAuth
.getSnapChatHandler('config.snapChat.clientId')
.validateUserCredentials({ authorizationCode: loginDto.authorizationCode });
Validate a Google ID token:
const payload = await ThirdAuth
.getGoogleHandler('config.google.clientId')
.validateUserCredentials({ idToken: loginDto.idToken });
Update Apple client secrets periodically:
await ThirdAuth.updateAppleClientSecrets();
Support multiple Apple, LinkedIn, Google and X (Twitter) accounts:
ThirdAuth.registerHandler({
clientId: 'config.apple.clientId.2',
clientSecret: 'config.apple.clientSecret.2',
keyId: 'config.apple.keyId.2',
teamId: 'config.apple.teamId.2',
privateKey: 'config.apple.privateKey.2',
}, ThirdPartyType.Apple);
const payload = await ThirdAuth
.getAppleHandler('config.apple.clientId.2')
.validateUserCredentials({ authorizationCode: loginDto.authorizationCode });
You can do the same for google and X (Twitter) to register more than one account and authorize users with the desired clientId.
This project is licensed under the MIT License.