Skip to content

Latest commit

 

History

History
83 lines (63 loc) · 1.68 KB

File metadata and controls

83 lines (63 loc) · 1.68 KB

Quick Start - Auth Middleware Submodule

Add to Your Microservice

# Add as submodule
git submodule add git@github.com:codephilip/authentication-middleware.git shared/auth-middleware

# Initialize
git submodule update --init --recursive

# Install dependencies
cd shared/auth-middleware && npm install && cd ../..

Update Your package.json

{
  "dependencies": {
    "auth-middleware": "file:./shared/auth-middleware"
  }
}

Use in Your Express App

const { initializeAuth } = require('./shared/auth-middleware/src/index');

const auth = initializeAuth({
  jwtSecret: process.env.JWT_SECRET,
  jwtRefreshSecret: process.env.JWT_REFRESH_SECRET,
  redisUrl: process.env.REDIS_URL,
  jwtAudience: 'your-service-name',
  jwtIssuer: 'auth-service'
});

// Apply middleware
app.use(...auth.essential);

// Protected route
app.get('/protected',
  auth.authenticate,
  auth.authorize(['READ']),
  (req, res) => res.json({ message: 'Protected' })
);

Update Submodule

# To latest version
git submodule update --remote shared/auth-middleware

# To specific version
cd shared/auth-middleware
git checkout v1.0.0
cd ../..
git add shared/auth-middleware
git commit -m "Update auth-middleware"

Environment Variables

JWT_SECRET=your-secret-key
JWT_REFRESH_SECRET=your-refresh-secret
REDIS_URL=redis://localhost:6379
JWT_AUDIENCE=your-service-name
JWT_ISSUER=auth-service

Available Versions

  • v1.0.0 - Production ready with submodule support

Documentation