Authentication¶
HANI supports multiple authentication modes to fit different deployment scenarios.
Configuration¶
Authentication is configured in ~/negmas/hani/settings/env.json:
{
"auth": {
"mode": "password",
"cookie_secret": "change-this-in-production",
"enforce_consent": false
}
}
Authentication Modes¶
Password Mode (Default)¶
Simple username/password authentication. Best for local development and small deployments.
Features:
- Users stored in
~/negmas/hani/settings/users.json - Default users:
admin/adminpassanduser/userpass - New users can register via
/registerendpoint - Passwords are hashed with bcrypt
Dual Mode¶
Both password and OAuth authentication. Users can choose their preferred login method.
{
"auth": {
"mode": "dual"
},
"oauth": {
"redirect_uri": "http://localhost:5006",
"providers": {
"github": {
"enabled": true,
"key": "your-github-client-id",
"secret": "your-github-client-secret"
},
"google": {
"enabled": true,
"key": "your-google-client-id",
"secret": "your-google-client-secret"
}
}
}
}
OAuth Mode¶
OAuth-only authentication. Users must log in via an OAuth provider.
Auto Mode¶
Automatically selects OAuth if configured, otherwise uses password:
Setting Up OAuth¶
GitHub OAuth¶
- Go to GitHub Developer Settings
- Click New OAuth App
- Fill in the application details:
- Application name: HANI (or your preferred name)
- Homepage URL:
http://localhost:5006(or your domain) - Authorization callback URL:
http://localhost:5006/oauth/callback - Click Register application
- Copy the Client ID and generate a Client Secret
- Add to your
env.json:
{
"oauth": {
"redirect_uri": "http://localhost:5006",
"providers": {
"github": {
"enabled": true,
"key": "your-client-id",
"secret": "your-client-secret"
}
}
}
}
Google OAuth¶
- Go to Google Cloud Console
- Create a new project or select an existing one
- Click Create Credentials → OAuth client ID
- Select Web application
- Add authorized redirect URI:
http://localhost:5006/oauth/callback - Copy the Client ID and Client Secret
- Add to your
env.json:
{
"oauth": {
"redirect_uri": "http://localhost:5006",
"providers": {
"google": {
"enabled": true,
"key": "your-client-id",
"secret": "your-client-secret"
}
}
}
}
Admin Access¶
Password Mode¶
The user admin has administrator privileges by default.
OAuth Mode¶
In OAuth mode, admin access is granted to users whose email is in the admin.emails list:
User Registration¶
Users can register at the /register endpoint. Registration creates a new entry in users.json.
To disable registration, you can modify the authentication handler or remove the registration route.
Consent Form¶
HANI can require users to consent before participating in negotiations:
When enabled, users must accept the consent form (located at ~/negmas/hani/settings/consent.md) before they can start negotiations.
Security Recommendations¶
Production Deployment
For production deployments:
- Change the cookie secret - Generate a secure random string
- Change default passwords - Never use
adminpassoruserpass - Use HTTPS - Configure a reverse proxy with SSL
- Restrict admin emails - Only add trusted emails to the admin list
Generating a Secure Cookie Secret¶
Add the generated value to your env.json:
Viewing Current Configuration¶
Run hani auth to see your current authentication configuration and setup instructions: