Skip to content

Instantly share code, notes, and snippets.

@claustres
Last active June 22, 2022 07:58
Show Gist options
  • Save claustres/651bcc7d4c298de61861b880fec93ef2 to your computer and use it in GitHub Desktop.
Save claustres/651bcc7d4c298de61861b880fec93ef2 to your computer and use it in GitHub Desktop.
OAuth backend configuration for Feathers v4
import _ from 'lodash'
import feathers from '@feathersjs/feathers'
import configuration from '@feathersjs/configuration'
import express from '@feathersjs/express'
import { AuthenticationService, JWTStrategy } from '@feathersjs/authentication'
import { LocalStrategy } from '@feathersjs/authentication-local'
import { AuthenticationProviderStrategy } from './AuthenticationProviderStrategy.js'
import { expressOauth } from '@feathersjs/authentication-oauth'
const app = express(feathers())
app.configure(configuration())
// Configure your app as usual (Express, Socket.io, etc.)
// ...
// Now configure local authentication and OAuth
const config = app.get('authentication')
const authentication = new AuthenticationService(app)
authentication.register('jwt', new JWTStrategy())
authentication.register('local', new LocalStrategy())
// Store available OAuth providers
app.authenticationProviders = _.keys(_.omit(config.oauth, ['redirect', 'origins']))
for (const provider of app.authenticationProviders) {
authentication.register(provider, new AuthenticationProviderStrategy())
}
app.use(config.path, authentication)
app.configure(expressOauth())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment