1.7.0 • Published 8 months ago

third-auth v1.7.0

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

ThirdAuth

ThirdAuth is a simple TypeScript library to securely validate third-party authentication with Apple, Google, X (Twitter), SnapChat and LinkedIn.

Features

  • Supports multiple Apple, LinkedIn, X (Twitter), SnapChat and Google Sign-In handlers
  • Manages different accounts with client IDs
  • Periodically updates Apple client secrets

Installation

npm install third-auth

Usage

Register a Handler

Apple Sign-In Handler

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);

X (Twitter) Sign-In Handler

Register a X (Twitter) Sign-In handler:

ThirdAuth.registerHandler({
  clientId: 'config.x.clientId',
  clientSecret: 'config.x.clientSecret',
  redirectURI: 'config.x.redirectURI',
}, ThirdPartyType.X);

LinkedIn Sign-In Handler

Register a LinkedIn Sign-In handler:

ThirdAuth.registerHandler({
  clientId: 'config.linkedIn.clientId',
  clientSecret: 'config.linkedIn.clientSecret',
  redirectURI: 'config.linkedIn.redirectURI',
}, ThirdPartyType.LinkedIn);

SnapChat Sign-In Handler

Register a SnapChat Sign-In handler:

ThirdAuth.registerHandler({
  clientId: 'config.snapChat.clientId',
  clientSecret: 'config.snapChat.clientSecret',
  redirectURI: 'config.snapChat.redirectURI',
}, ThirdPartyType.SnapChat);

Google Sign-In Handler

Register a Google Sign-In handler:

ThirdAuth.registerHandler({
  clientId: 'config.google.clientId',
  clientSecret: 'config.google.clientSecret',
}, ThirdPartyType.Google);

Validate User Credentials

Apple

Validate an Apple authorization code:

const payload = await ThirdAuth
  .getAppleHandler('config.apple.clientId')
  .validateUserCredentials({ authorizationCode: loginDto.authorizationCode });

X (Twitter)

Validate a X (Twitter) authorization code:

const payload = await ThirdAuth
  .getXHandler('config.x.clientId')
  .validateUserCredentials({ authorizationCode: loginDto.authorizationCode });

LinkedIn

Validate a LinkedIn authorization code:

const payload = await ThirdAuth
  .getLinkedInHandler('config.linkedIn.clientId')
  .validateUserCredentials({ authorizationCode: loginDto.authorizationCode });

SnapChat

Validate a SnapChat authorization code:

const payload = await ThirdAuth
  .getSnapChatHandler('config.snapChat.clientId')
  .validateUserCredentials({ authorizationCode: loginDto.authorizationCode });

Google

Validate a Google ID token:

const payload = await ThirdAuth
  .getGoogleHandler('config.google.clientId')
  .validateUserCredentials({ idToken: loginDto.idToken });

Update Apple Client Secrets

Update Apple client secrets periodically:

await ThirdAuth.updateAppleClientSecrets();

Multiple Apple Sign-In Handlers

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.

License

This project is licensed under the MIT License.

1.7.0

8 months ago

1.6.0

8 months ago

1.5.0

8 months ago

1.4.0

8 months ago

1.3.0

10 months ago

1.2.6

10 months ago

1.2.5

10 months ago

1.2.4

10 months ago

1.2.3

10 months ago

1.2.2

10 months ago

1.2.1

10 months ago

1.2.0

10 months ago

1.1.2

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.0

10 months ago