Getting started
Authentication
Secure user authentication, OAuth 2.0 integration, session management, and role-based access control in OutRiskAI.
OutRiskAI employs NextAuth.js v5 to manage secure session-based authentication for the web dashboard and token-based authentication for the Public REST API.
Web application sessions use encrypted, HTTP-only cookies. Public API integrations authenticate using Bearer secret tokens (ork_live_...).
Supported Authentication Methods
- OAuth 2.0 Single Sign-On: Google OAuth & LinkedIn Sign-In.
- Credentials Authentication: Email and bcrypt-hashed passwords.
- API Secret Keys: Scoped Bearer tokens generated from user profiles (
/profile).
NextAuth.js Environment Setup
Ensure the following authentication variables are defined in your .env file:
# NextAuth Core Settings
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-32-byte-base64-secret"
# Google OAuth Provider
GOOGLE_CLIENT_ID="123456789-example.apps.googleusercontent.com"
GOOGLE_CLIENT_SECRET="GOCSPX-example_secret"Configuring Google OAuth
- Navigate to the Google Cloud Console Credentials page.
- Create a new OAuth 2.0 Client ID with application type Web application.
- Add Authorized JavaScript Origins:
http://localhost:3000(Development)https://your-domain.com(Production)
- Add Authorized Redirect URIs:
http://localhost:3000/api/auth/callback/googlehttps://your-domain.com/api/auth/callback/google
- Copy the generated Client ID and Client Secret into
.env.
Role-Based Access Control (RBAC)
OutRiskAI enforces three primary user roles:
| Role | Permissions |
|---|---|
| USER | Upload contracts, trigger AI analysis, chat with contracts, manage owned API keys. |
| LAWYER | Review assigned user contracts, offer professional legal consultations, publish recommendations. |
| ADMIN | Full system access, manage user roles, audit platform metrics, configure system defaults. |
Session Storage & Security Standards
- Cookie Security: Cookies are flagged
SameSite=Lax,HttpOnly, andSecure(in production HTTPS). - Password Hashing: Passwords are hashed using
bcryptwith a salt round factor of 12. - API Key Hashing: Secret API keys are shown once at creation. Only a SHA-256 hash of the token is stored in PostgreSQL.