{"library":"passport-sendoso-postilize","title":"Passport Sendoso OAuth 2.0 Strategy","description":"This package provides a Passport authentication strategy specifically designed for integrating with Sendoso using the OAuth 2.0 protocol. It enables Node.js applications, particularly those leveraging Connect-style middleware such as Express, to authenticate users via their Sendoso accounts. The current stable version is 1.0.2, indicating a specific, potentially specialized or modified, integration rather than a general-purpose, high-cadence library. Its key differentiator is its direct focus on Sendoso's unique authentication flow, offering a structured way to connect Passport.js applications to Sendoso for user identity verification. Developers must provide a `clientID`, `clientSecret`, and `callbackURL` to configure the strategy, and a `verify` callback to handle user data after successful authentication. This package simplifies the OAuth 2.0 handshake for Sendoso, allowing Passport's robust session management and user serialization features to be applied.","language":"javascript","status":"maintenance","last_verified":"Wed Apr 22","install":{"commands":["npm install passport-sendoso-postilize"],"cli":null},"imports":["import { Strategy as SendosoStrategy } from 'passport-sendoso-postilize';","import passport from 'passport';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const express = require('express');\nconst passport = require('passport');\nconst session = require('express-session'); // Required for Passport sessions\nconst { Strategy: SendosoStrategy } = require('passport-sendoso-postilize'); // Using destructuring for clarity\n\nconst app = express();\n\n// Passport configuration\npassport.use(new SendosoStrategy({\n    clientID:     process.env.SENDOSO_CLIENT_ID ?? 'YOUR_SENDOSO_CLIENT_ID',\n    clientSecret: process.env.SENDOSO_CLIENT_SECRET ?? 'YOUR_SENDOSO_CLIENT_SECRET',\n    callbackURL:  \"http://localhost:3000/auth/sendoso/callback\",\n    passReqToCallback: true\n  },\n  function(request, accessToken, refreshToken, profile, done) {\n    // In a real application, you would typically find or create a user in your database\n    // based on the profile information returned by Sendoso.\n    // The 'profile' object would contain user details provided by Sendoso.\n    // For demonstration, we'll return a placeholder user.\n    const user = { id: profile?.id || 'sendoso_user_123', name: profile?.displayName || 'Sendoso User' };\n    console.log('Sendoso Profile:', profile);\n    console.log('Access Token:', accessToken);\n    done(null, user); // Call done with null for error and the user object\n  }\n));\n\n// Passport session setup.\n//   To support persistent login sessions, Passport needs to be able to\n//   serialize users into and deserialize users out of the session.\n//   Typically, this will be as simple as storing the user ID when serializing\n//   and finding the user by ID when deserializing.\npassport.serializeUser(function(user, done) {\n  done(null, user.id);\n});\n\npassport.deserializeUser(function(id, done) {\n  // In a real application, retrieve user from database by ID\n  const user = { id: id, name: 'Deserialized User' }; // Placeholder\n  done(null, user);\n});\n\n// Middleware for Express\napp.use(session({ secret: 'keyboard cat', resave: false, saveUninitialized: false }));\napp.use(passport.initialize());\napp.use(passport.session());\n\n// Define authentication routes\napp.get('/auth/sendoso',\n  passport.authenticate('sendoso', { scope: 'profile email' } // Replace 'profile email' with actual Sendoso scopes if available\n));\n\napp.get('/auth/sendoso/callback',\n  passport.authenticate('sendoso', {\n    successRedirect: '/profile', // Redirect to a profile page on success\n    failureRedirect: '/login'    // Redirect to login on failure\n  })\n);\n\napp.get('/profile', (req, res) => {\n  if (req.isAuthenticated()) {\n    res.send(`<h1>Welcome, ${req.user.name || 'authenticated user'}!</h1><pre>${JSON.stringify(req.user, null, 2)}</pre><p><a href=\"/logout\">Logout</a></p>`);\n  } else {\n    res.redirect('/login');\n  }\n});\n\napp.get('/login', (req, res) => {\n  res.send('<h1>Login with Sendoso</h1><p><a href=\"/auth/sendoso\">Login with Sendoso</a></p>');\n});\n\napp.get('/logout', (req, res, next) => {\n  req.logout((err) => {\n    if (err) { return next(err); }\n    res.redirect('/login');\n  });\n});\n\nconst PORT = 3000;\napp.listen(PORT, () => {\n  console.log(`Server running on http://localhost:${PORT}`);\n  console.log('Visit http://localhost:3000/login to start the authentication flow.');\n});","lang":"javascript","description":"Demonstrates how to configure and use the Passport-Sendoso-postilize strategy with Express, including session management, authentication routes, and user serialization/deserialization.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}