
Product
Announcing Bun and vlt Support in Socket
Bringing supply chain security to the next generation of JavaScript package managers
@travetto/auth-rest-passport
Advanced tools
Rest authentication integration support for the Travetto framework
Install: @travetto/auth-rest-passport
npm install @travetto/auth-rest-passport
# or
yarn add @travetto/auth-rest-passport
This is a primary integration for the Rest Auth module. This is another level of scaffolding allowing for compatible authentication frameworks to integrate.
Within the node ecosystem, the most prevalent auth framework is passport. With countless integrations, the desire to leverage as much of it as possible, is extremely high. To that end, this module provides support for passport baked in. Registering and configuring a passport strategy is fairly straightforward.
Code: Sample Facebook/passport config
import { Strategy as FacebookStrategy } from 'passport-facebook';
import { InjectableFactory } from '@travetto/di';
import { Authenticator, Authorizer, Principal } from '@travetto/auth';
import { PassportAuthenticator } from '@travetto/auth-rest-passport';
export class FbUser {
username: string;
permissions: string[];
}
export const FB_AUTH = Symbol.for('auth_facebook');
export class AppConfig {
@InjectableFactory(FB_AUTH)
static facebookPassport(): Authenticator {
return new PassportAuthenticator('facebook',
new FacebookStrategy(
{
clientID: '<appId>',
clientSecret: '<appSecret>',
callbackURL: 'http://localhost:3000/auth/facebook/callback',
profileFields: ['id', 'username', 'displayName', 'photos', 'email'],
},
(accessToken, refreshToken, profile, cb) =>
cb(undefined, profile)
),
(user: FbUser) => ({
id: user.username,
permissions: user.permissions,
details: user
})
);
}
@InjectableFactory()
static principalSource(): Authorizer {
return new class implements Authorizer {
async authorize(p: Principal) {
return p;
}
}();
}
}
As you can see, PassportAuthenticator will take care of the majority of the work, and all that is required is:
Note: You will need to provide the callback for the strategy to ensure you pass the external principal back into the framework After that, the provider is no different than any other, and can be used accordingly. Additionally, because passport runs first, in it's entirety, you can use the provider as you normally would any passport middleware.
Code: Sample routes using Facebook/passport provider
import { Controller, Get, Redirect, Post, Request } from '@travetto/rest';
import { Login, Authenticated, Logout } from '@travetto/auth-rest';
import { FB_AUTH } from './conf';
@Controller('/auth')
export class SampleAuth {
@Get('/name')
async getName() {
return { name: 'bob' };
}
@Get('/facebook')
@Login(FB_AUTH)
async fbLogin() {
}
@Get('/self')
@Authenticated()
async getSelf(req: Request) {
return req.auth;
}
@Get('/facebook/callback')
@Login(FB_AUTH)
async fbLoginComplete() {
return new Redirect('/auth/self', 301);
}
@Post('/logout')
@Logout()
async logout() { }
/**
* Simple Echo
*/
@Post('/')
async echo(req: Request): Promise<object> {
return req.body;
}
}
FAQs
Rest authentication integration support for the Travetto framework
We found that @travetto/auth-rest-passport demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Bringing supply chain security to the next generation of JavaScript package managers

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies

Product
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.