Grant Express is an Express.js middleware that acts as a handler for the Grant OAuth Proxy, simplifying authentication and authorization flows within Node.js applications. It integrates the robust Grant core library, which provides universal OAuth support for over 200 providers including Google, GitHub, Facebook, and many others. The current stable version for `grant-express` is 5.4.8. Grant is designed to abstract away the complexities of OAuth 1.0a, 2.0, and OpenID Connect, offering a unified configuration system and flexible integration with various HTTP frameworks and serverless environments. Its key differentiators include broad provider compatibility, a declarative configuration approach, and its ability to function as an embeddable OAuth client. The package facilitates managing OAuth callbacks, tokens, and session state efficiently, though users must provide their own session store. Release cadence is tied to the underlying Grant core library, which is actively maintained with updates for new providers, OAuth specification changes, and security patches.
npm install grant-expressVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up Grant Express middleware with a basic Express server and GitHub OAuth for user authentication, including session management and environment variable usage for credentials.
Review your Express application for v5 breaking changes. Ensure `grant` (the core library) is updated to its latest version, which typically includes compatibility fixes for newer Express releases. Test thoroughly after upgrading `express`.
Install and configure `express-session` (or a compatible session store) and ensure `app.use(session(...))` is called *before* `app.use(Grant(...))` in your Express application's middleware chain.
Always use environment variables, a secrets management service, or a secure configuration file to load sensitive credentials. Tools like `dotenv` can help manage environment variables in development.
Carefully verify that the `origin` and `prefix` in your Grant configuration, along with the specific provider's `callback` path, exactly match what you have configured in the OAuth provider's developer settings.
Monitor the `grant` (core) repository for updates and breaking changes, as `grant-express` effectively wraps its functionality. If new Express versions or critical Node.js environment changes cause issues, direct contribution or seeking updates to `grant-express` itself may be necessary.
Ensure `express-session` (or an equivalent session management middleware) is installed and configured using `app.use(session({ ... }))` *before* mounting `grant-express` with `app.use(Grant(config))`.Double-check your Grant configuration (`origin`, `prefix`, and provider `callback`) and compare it precisely with the Authorized Redirect URIs listed in your OAuth provider's application settings. Pay attention to `http` vs `https`, domain, port, and path segments.
For ES Modules, use `import Grant from 'grant-express';`. For CommonJS, use `const Grant = require('grant-express');`. Ensure you are calling the imported `Grant` function to create the middleware, e.g., `app.use(Grant(config))`.Verify that `app.use(Grant(config))` is called correctly in your Express setup. Confirm that the `prefix` in your `grantConfig` matches the base path from which you expect Grant to handle routes (e.g., if `prefix: '/auth'`, then `/auth/github` would initiate the flow).