Coder Social home page Coder Social logo

mjangir / nestjs-hybrid-auth Goto Github PK

View Code? Open in Web Editor NEW
62.0 2.0 13.0 700 KB

Open source social sign in NestJS. NestJS HybridAuth works with various identities providers such as Facebook, Twitter, Google and many more. It use passport authentication under the hood.

Home Page: https://nestjs-hybrid-auth.manishjangir.com/

License: MIT License

TypeScript 27.38% JavaScript 6.65% CSS 2.82% Shell 0.04% MDX 63.11%
nestjs passportjs passport-google passport-twitter nestjs-auth nestjs-google hectoberfest hectoberfest2021

nestjs-hybrid-auth's Introduction

NestJS Hybrid Auth

NestJS Hybrid Auth

npm type definitions npm compressed size GitHub

NestJS hybrid auth is a dynamic nestjs module or assembling of individual modules written over passport authentication library which enables you to integrate social login in your nestjs application for various identity providers such as Facebook, Google, Instagram and many more.

Please visit https://nestjs-hybrid-auth.manishjangir.com for complete documentation

Prerequisites

The library requires you to install few peer dependencies

npm install @nestjs/passport passport reflect-metadata --save

OR

yarn add @nestjs/passport passport reflect-metadata

Install Hybrid Auth

You can install the library for all providers or install it separately for each identity provider.

For All Providers

npm install @nestjs-hybrid-auth/all --save
yarn add @nestjs-hybrid-auth/all

For Individual Identity

npm install @nestjs-hybrid-auth/google --save
yarn add @nestjs-hybrid-auth/google

How To Use?

Every individual package or the global all-in-one hybrid auth package exports a dynamic nestjs module and nest Guard (controller method decorator) which sets up the login and callback workflow.

Note: This is just a usage snippet. Please read the actual documentation of an identity provider for its peer dependencies.

In *.module.ts file

If you are using individual package

import { GoogleAuthModule } from '@nestjs-hybrid-auth/google';

@Module({
  import: [
    GoogleAuthModule.forRoot({
      clientID: 'xxxxxxxxxxxx',
      clientSecret: 'xxxxxxxxxx',
      requestCallbackURL: 'xxxxxxxxx',
    }),
  ],
})
class AppModule {}

Or if you are using all-in-one package

import { HybridAuthModule } from '@nestjs-hybrid-auth/all';

@Module({
  import: [
    HybridAuthModule.forRoot({
      google: {
        clientID: 'xxxxxxxxxxxx',
        clientSecret: 'xxxxxxxxxx',
        requestCallbackURL: 'xxxxxxxxx',
      },
    }),
  ],
})
class AppModule {}

In *.controller.ts file

import { UseGoogleAuth } from '@nestjs-hybrid-auth/google';
// OR
import { UseGoogleAuth } from '@nestjs-hybrid-auth/all';

@Controller
class AuthController {
  @UseGoogleAuth()
  @Get('auth/google')
  googleLogin() {}

  @UseGoogleAuth()
  @Get('auth/google-callback') // This is the route configured in your Google oauth app
  googleLoginCallback(req: Request) {
    console.log(req.hybridAuthResult.user | accessToken | refreshToken);
  }
}

Note:

  1. As passport uses express under the hood, fastify applications may not work with this package.
  2. Please read the full documentation for an identity provider before using it because some providers may require few additional dependencies to be installed to work properly.

Supported Identity Providers (Many more are yet to come)

Related

Maintainers & Contributors

Manish Jangir

Credits

Gopendra Jangir (Banner Image)

nestjs-hybrid-auth's People

Contributors

github-actions[bot] avatar mjangir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nestjs-hybrid-auth's Issues

[Twitch] 'uuid' problem

Bug report

Current Behavior

Currently, when I install this package and set up the routes as per the documentation, the app fails to compile due to the following error:

Error: Package subpath './v4' is not defined by "exports" in <APP_PATH>\node_modules\uuid\package.json
    at new NodeError (node:internal/errors:387:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:439:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:718:3)
    at resolveExports (node:internal/modules/cjs/loader:493:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:533:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:942:27)
    at Function.Module._load (node:internal/modules/cjs/loader:804:27)
    at Function.Module._load (<APP_PATH>\packages\node\src\executors\node\node-with-require-overrides.ts:16:27)
    at Module.require (node:internal/modules/cjs/loader:1022:19)
    at require (node:internal/modules/cjs/helpers:102:18)

If I remove any reference to this package, it works fine (albeit without authentication obviously).

I noticed that something required by this package uses a very old version of uuid, because when installing this, I get the warning: npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic.. Using npm ls uuid shows that [email protected] which depends on [email protected] (which in itself is deprecated) uses [email protected] which is horribly out of date and deprecated, and this package depends on passport-twitch-latest (which hasn't been updated for over 2 years).

Expected behavior

I expect for it to work as described

Suggested solution(s)

I believe changing to not use something that has a very out of date dependency of uuid will work (for example, this one, which doesn't use request at all, so no uuid dependency), since everything in nestjs uses [email protected], and in version 7 of uuid, using subpaths was deprecated and in version 8 it was removed entirely (hence the ./v4 error above I believe).

Additional context

I'll also put this here, but if you want a separate issue let me know, but it would be nice to officially support v9 of nestjs and v0.6 of passport, since this package has a dependency of nestjs@^8.0.7 and passport@^0.5.0and I want to keep my packages updated without loads of warnings and I don't like having to use --force. And on top of that, [email protected] is deprecated due to a security issue (Passport before 0.6.0 vulnerable to session regeneration when a users logs in or out - https://github.com/advisories/GHSA-v923-w3x8-wh69), but I suppose if you move away from passport-twitch-latest to a more up-to-date alternative or make your own, that will most likely be fixed (although my suggestion above still depends on passport@^0.5.0 but maybe forcing to use 0.6.0 will work).

Your environment

Software Version(s)
@nestjs-hybrid-auth/twitch 1.0.0
@nestjs/core 8.4.7
@nestjs/common 8.4.7
@nestjs/passport 8.2.2
passport 0.5.3
npm 8.13.2
Operating System Windows 10 Pro

Twitch provider

Hey! ๐Ÿ‘‹ this is super cool! And extremely useful! I use Nest and have been looking at using https://github.com/supabase/gotrue for an OAuth server. And then I found this, perfect!

And now for my request, could you add the Twitch provider? I use https://github.com/Nigh7Sh4de/passport-twitch-new currently. With some time I could implement it myself, but I wanted to post this issue first in case someone else gets to it before me.

Note: You should add the hacktoberfest topic to this repo to make it eligible for the event!

Shopify Login || Extensible config

This is an awesome package and just what i've been looking for. Cheers!

Unfortunately I need a Shopify Auth and I see this is the 2nd feature request in a very short time :D

If Shopify Auth is not possible, is it possible to make the package extensible with our own configs?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.