open-index/open-npm huggingface dataset:
npm package: @ioleksiy/nocobase-oauth2-proxy-auth
Description: oAuth2-Proxy plugin: authenticate via oauth2-proxy headers and enforce user existence
Latest version: 1.8.4

# NocoBase OAuth2 Proxy Auth

Authenticate NocoBase requests against users provisioned in your database when fronted by [oauth2-proxy](https://oauth2-proxy.github.io/oauth2-proxy/). The plugin inspects the `x-auth-request-email` header provided by oauth2-proxy, verifies that the user exists, and attaches the user to the NocoBase request context.

## Installation

```bash
npm install @ioleksiy/nocobase-oauth2-proxy-auth
```

> **Compatibility**
>
> Requires `@nocobase/server` version `>=0.19.0 <2.0.0` (includes the current `1.x` releases).

## Usage

Register the plugin inside your NocoBase application. The middleware will:

1. Read the `x-auth-request-email` header set by oauth2-proxy after a successful login.
2. Look up the matching user inside the `users` repository.
3. Reject the request with `401` if the header is missing or `403` if the user doesn't exist.
4. Attach the user to `ctx.state.currentUser` for downstream handlers.

```js
const oauth2ProxyAuth = require('@ioleksiy/nocobase-oauth2-proxy-auth');

module.exports = ({ app }) => {
  app.plugin(oauth2ProxyAuth);
};
```

Make sure oauth2-proxy is configured to forward the `X-Auth-Request-Email` header and that the users authenticated through oauth2-proxy also exist in your NocoBase instance.

## Development

- Update the package version in `package.json` before publishing new releases.
- The repository includes a GitHub Actions workflow that automatically publishes the package to npm when commits are pushed to the `main` branch or when the workflow is triggered manually. Configure the `NPM_TOKEN` secret in the repository to enable automated publishing.

## License

MIT