This repository is a standalone Authorization/Authentication library extracted from the cheese project. It offers a comprehensive, ready-to-use authentication solution that not only provides basic features such as email-based registration and password reset but also includes advanced functionalities like user avatars and mutual following between users.
The repository consists of two parts: the first is an Auth Server simplified from cheese-backend, and the second is an Auth library separated from cheese-backend-nt, which can be used with the first Auth Server in any SpringBoot project.
Cheese-Auth supports dynamically loading OAuth providers through a flexible plugin system, which allows you to easily add new OAuth providers without modifying the core code.
Configure the following environment variables in your .env file:
# Enabled OAuth providers (comma-separated list)
OAUTH_ENABLED_PROVIDERS=provider1,provider2
# Search paths for provider implementations (comma-separated list)
OAUTH_PLUGIN_PATHS=plugins/oauth,dist/oauth-providers
# Configuration for each provider
OAUTH_PROVIDER1_CLIENT_ID=your-client-id
OAUTH_PROVIDER1_CLIENT_SECRET=your-client-secret
OAUTH_PROVIDER1_REDIRECT_URL=your-redirect-url
You can implement OAuth providers in several ways:
Create a JavaScript file in the plugins/oauth directory:
// plugins/oauth/provider1.js (CommonJS) or provider1.mjs (ES Module)
// CommonJS format
function createProvider(clientId, clientSecret, redirectUrl) {
// Return provider instance
return new YourProviderImplementation(clientId, clientSecret, redirectUrl);
}
module.exports = {
createProvider,
id: 'provider1' // Optional, helps with factory function discovery
};
// OR ES Module format:
export function createProvider(clientId, clientSecret, redirectUrl) {
return new YourProviderImplementation(clientId, clientSecret, redirectUrl);
}
export default createProvider;Organize your provider in a directory with an index file:
plugins/oauth/provider1/
├── index.js # Main entry point
├── api.js # API implementation
└── utils.js # Helper functions
For Docker environments or when distributing pre-built providers:
- Build your provider implementation
- Copy the compiled files to
dist/oauth-providers/provider1/ - Ensure there's an
index.jsfile that exports the provider factory
The system will search for providers in multiple locations:
- First in all configured paths in
OAUTH_PLUGIN_PATHS - If not found, as a fallback it will try to load from npm packages
For each provider, it looks for a factory function in this order:
defaultexportcreateProviderexportcreateexportcreateXxxOAuthProviderfunction (where Xxx is the capitalized provider ID)
See the following examples for reference:
plugins/oauth/ruc.js- Simple CommonJS implementationplugins/oauth/ruc.mjs- ES Module implementationdist/oauth-providers/ruc/- Pre-built provider example