Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@nestjs-hybrid-auth/all
Advanced tools
Readme
Implement various social identity provider authentication in your NestJS application for e.g. Google, Facebook, Twitter and many more.
npm install @nestjs-hybrid-auth/all --save
OR
yarn add @nestjs-hybrid-auth/all
This package is an assembling of all the individual nestjs hybrid auth provider packages and exports one single dynamic nestjs module. The module takes configuration for all social providers both synchronously and asynchronously using forRoot
and forRootAsync
static methods.
If you have all of your social providers credentials and configuration handy in an object, just pass them in .forRoot
static method to register the module. The options object is type of HybridAuthModuleOptions
.
import { HybridAuthModule } from '@nestjs-hybrid-auth/all';
@Module({
imports: [
HybridAuthModule.forRoot({
google: {
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: process.env.GOOGLE_CALLBACK_URL,
},
facebook: {
clientID: process.env.FACEBOOK_CLIENT_ID,
clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
callbackURL: process.env.FACEBOOK_CALLBACK_URL,
},
// Rest of the providers
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
If you get the configurations for each identity provider asynchronously through any config service or so, use forRootAsync
static method to load them. The options would be same but value for each provider would be their AsyncOptions equivalent. Please refer to below code:
useFactory
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import {
HybridAuthModule,
FacebookAuthModuleOptions,
} from '@nestjs-hybrid-auth/all';
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
cache: true,
expandVariables: true,
}),
HybridAuthModule.forRootAsync({
facebook: {
useFactory: (
configService: ConfigService
): FacebookAuthModuleOptions => ({
clientID: configService.get('FACEBOOK_CLIENT_ID'),
clientSecret: configService.get('FACEBOOK_CLIENT_SECRET'),
callbackURL: configService.get('FACEBOOK_CALLBACK_URL'),
}),
inject: [ConfigService],
},
// Rest of the providers
}),
],
})
export class AllAsyncFactoryModule {}
useClass
import { Module, Injectable } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import {
HybridAuthModule,
FacebookAuthModuleOptions,
FacebookAuthModuleOptionsFactory,
} from '@nestjs-hybrid-auth/all';
// We create a config provider class for useClass
@Injectable()
export class FacebookAuthConfig implements FacebookAuthModuleOptionsFactory {
constructor(private configService: ConfigService) {}
createModuleOptions(): FacebookAuthModuleOptions {
return {
clientID: this.configService.get('FACEBOOK_CLIENT_ID'),
clientSecret: this.configService.get('FACEBOOK_CLIENT_SECRET'),
callbackURL: this.configService.get('FACEBOOK_CALLBACK_URL'),
};
}
}
// Actual app module
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
cache: true,
expandVariables: true,
}),
HybridAuthModule.forRootAsync({
facebook: {
useClass: FacebookAuthConfig,
},
// Rest of the providers
}),
],
})
export class AllAsyncClassModule {}
@nestjs-hybrid-auth/all
just re-exports all the authentication route guards and result interfaces from all the individual identity providers. For more information, you can check the documentation for any provider for e.g.@nestjs-hybrid-auth/google
.
If you still have trouble setting up the workflow properly, please file an issue at Issues page.
FAQs
NestJS social authentication provider using passportJS
The npm package @nestjs-hybrid-auth/all receives a total of 29 weekly downloads. As such, @nestjs-hybrid-auth/all popularity was classified as not popular.
We found that @nestjs-hybrid-auth/all demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.