npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

third-auth

v1.7.0

Published

NPM server-side third party authentication library for sign in with apple, sign in with google, sign in with X (twitter) and sign in with LinkedIn in typescript

Downloads

385

Readme

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.