aven 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/app/components/aven/views/oauth/error/component.html.erb +44 -0
- data/app/components/aven/views/oauth/error/component.rb +30 -0
- data/app/components/aven/views/static/index/component.html.erb +4 -4
- data/app/components/aven/views/static/index/component.rb +11 -0
- data/app/controllers/aven/admin/base.rb +4 -4
- data/app/controllers/aven/application_controller.rb +22 -0
- data/app/controllers/aven/auth_controller.rb +6 -58
- data/app/controllers/aven/oauth/auth0_controller.rb +84 -0
- data/app/controllers/aven/oauth/base_controller.rb +183 -0
- data/app/controllers/aven/oauth/documentation/auth0.md +387 -0
- data/app/controllers/aven/oauth/documentation/entra_id.md +608 -0
- data/app/controllers/aven/oauth/documentation/github.md +329 -0
- data/app/controllers/aven/oauth/documentation/google.md +253 -0
- data/app/controllers/aven/oauth/entra_id_controller.rb +92 -0
- data/app/controllers/aven/oauth/github_controller.rb +91 -0
- data/app/controllers/aven/oauth/google_controller.rb +64 -0
- data/app/controllers/aven/workspaces_controller.rb +20 -0
- data/app/controllers/concerns/aven/authentication.rb +49 -0
- data/app/controllers/concerns/aven/controller_helpers.rb +38 -0
- data/app/helpers/aven/application_helper.rb +2 -6
- data/app/models/aven/app_record.rb +1 -1
- data/app/models/aven/app_record_schema.rb +0 -1
- data/app/models/aven/log.rb +0 -1
- data/app/models/aven/loggable.rb +2 -3
- data/app/models/aven/user.rb +0 -23
- data/app/models/aven/workspace.rb +49 -5
- data/app/models/aven/workspace_role.rb +0 -1
- data/app/models/aven/workspace_user.rb +0 -1
- data/app/models/aven/workspace_user_role.rb +0 -1
- data/config/routes.rb +22 -7
- data/db/migrate/{20251003090752_create_aven_users.rb → 20200101000001_create_aven_users.rb} +1 -1
- data/db/migrate/{20251004182010_create_aven_workspace_users.rb → 20200101000003_create_aven_workspace_users.rb} +1 -1
- data/db/migrate/{20251004182020_create_aven_workspace_roles.rb → 20200101000004_create_aven_workspace_roles.rb} +1 -1
- data/db/migrate/{20251004182030_create_aven_workspace_user_roles.rb → 20200101000005_create_aven_workspace_user_roles.rb} +1 -1
- data/db/migrate/{20251004190000_create_aven_logs.rb → 20200101000006_create_aven_logs.rb} +2 -3
- data/db/migrate/{20251004190100_create_aven_app_record_schemas.rb → 20200101000007_create_aven_app_record_schemas.rb} +0 -1
- data/db/migrate/{20251004190110_create_aven_app_records.rb → 20200101000008_create_aven_app_records.rb} +0 -1
- data/lib/aven/configuration.rb +26 -10
- data/lib/aven/engine.rb +15 -16
- data/lib/aven/model/tenant_model.rb +91 -0
- data/lib/aven/model.rb +6 -0
- data/lib/aven/version.rb +1 -1
- metadata +42 -69
- data/config/initializers/devise.rb +0 -43
- /data/db/migrate/{20251004182000_create_aven_workspaces.rb → 20200101000002_create_aven_workspaces.rb} +0 -0
- /data/lib/tasks/{sqema_tasks.rake → aven_tasks.rake} +0 -0
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
# Auth0 OAuth Implementation Documentation
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Auth0 OAuth 2.0 integration for the Aven application. Auth0 is an identity-as-a-service platform that supports multiple identity providers (social, enterprise, database) through a single integration.
|
|
6
|
+
|
|
7
|
+
**Controller**: `app/controllers/aven/oauth/auth0_controller.rb`
|
|
8
|
+
**Routes**: `config/routes.rb:26-28`
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Default Scopes
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
openid email profile
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Scope Breakdown
|
|
19
|
+
|
|
20
|
+
| Scope | Purpose | Admin Consent Required |
|
|
21
|
+
|-------|---------|------------------------|
|
|
22
|
+
| `openid` | OpenID Connect authentication | No |
|
|
23
|
+
| `email` | Access user's email address | No |
|
|
24
|
+
| `profile` | Access user's basic profile | No |
|
|
25
|
+
|
|
26
|
+
**Note**: These are standard OIDC scopes. Auth0 doesn't require admin approval for these basic scopes.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## OAuth 2.0 Flow
|
|
31
|
+
|
|
32
|
+
### 1. Authorization Request
|
|
33
|
+
|
|
34
|
+
**Endpoint**: `https://{your-domain}.auth0.com/authorize`
|
|
35
|
+
|
|
36
|
+
**Parameters**:
|
|
37
|
+
```ruby
|
|
38
|
+
{
|
|
39
|
+
client_id: "YOUR_CLIENT_ID",
|
|
40
|
+
redirect_uri: "https://yourdomain.com/oauth/auth0/callback",
|
|
41
|
+
response_type: "code",
|
|
42
|
+
scope: "openid email profile",
|
|
43
|
+
state: "RANDOM_STATE_TOKEN",
|
|
44
|
+
audience: "YOUR_API_IDENTIFIER" # Optional: for API access
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 2. Token Exchange
|
|
49
|
+
|
|
50
|
+
**Endpoint**: `https://{your-domain}.auth0.com/oauth/token`
|
|
51
|
+
|
|
52
|
+
**Parameters**:
|
|
53
|
+
```ruby
|
|
54
|
+
{
|
|
55
|
+
grant_type: "authorization_code",
|
|
56
|
+
client_id: "YOUR_CLIENT_ID",
|
|
57
|
+
client_secret: "YOUR_CLIENT_SECRET",
|
|
58
|
+
code: "AUTHORIZATION_CODE",
|
|
59
|
+
redirect_uri: "https://yourdomain.com/oauth/auth0/callback"
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 3. User Info Retrieval
|
|
64
|
+
|
|
65
|
+
**Endpoint**: `https://{your-domain}.auth0.com/userinfo`
|
|
66
|
+
|
|
67
|
+
**Response**:
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"sub": "auth0|1234567890abcdef",
|
|
71
|
+
"email": "user@example.com",
|
|
72
|
+
"email_verified": true,
|
|
73
|
+
"name": "John Doe",
|
|
74
|
+
"nickname": "johndoe",
|
|
75
|
+
"picture": "https://s.gravatar.com/avatar/..."
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Configuration
|
|
82
|
+
|
|
83
|
+
### Application Configuration
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
config.oauth_providers = {
|
|
87
|
+
auth0: {
|
|
88
|
+
client_id: ENV['AUTH0_CLIENT_ID'],
|
|
89
|
+
client_secret: ENV['AUTH0_CLIENT_SECRET'],
|
|
90
|
+
domain: ENV['AUTH0_DOMAIN'], # e.g., "your-tenant.auth0.com"
|
|
91
|
+
# Optional configurations:
|
|
92
|
+
scope: "openid email profile",
|
|
93
|
+
audience: ENV['AUTH0_AUDIENCE'] # Optional: for API access
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Environment Variables
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
AUTH0_CLIENT_ID=a1b2c3d4e5f6g7h8i9j0k1l2
|
|
102
|
+
AUTH0_CLIENT_SECRET=A1B2C3D4E5F6G7H8I9J0K1L2M3N4O5P6Q7R8S9T0
|
|
103
|
+
AUTH0_DOMAIN=your-tenant.auth0.com
|
|
104
|
+
AUTH0_AUDIENCE=https://yourapi.com/api # Optional
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Auth0 Application Setup
|
|
110
|
+
|
|
111
|
+
### 1. Create Application
|
|
112
|
+
|
|
113
|
+
1. Go to [Auth0 Dashboard](https://manage.auth0.com)
|
|
114
|
+
2. Navigate to **Applications** > **Applications**
|
|
115
|
+
3. Click **Create Application**
|
|
116
|
+
4. Choose:
|
|
117
|
+
- **Name**: Your application name
|
|
118
|
+
- **Application Type**: Regular Web Application
|
|
119
|
+
5. Click **Create**
|
|
120
|
+
|
|
121
|
+
### 2. Configure Application Settings
|
|
122
|
+
|
|
123
|
+
1. Go to **Settings** tab
|
|
124
|
+
2. Configure:
|
|
125
|
+
- **Allowed Callback URLs**: `https://yourdomain.com/oauth/auth0/callback`
|
|
126
|
+
- **Allowed Logout URLs**: `https://yourdomain.com`
|
|
127
|
+
- **Allowed Web Origins**: `https://yourdomain.com`
|
|
128
|
+
3. Scroll to bottom and click **Save Changes**
|
|
129
|
+
|
|
130
|
+
### 3. Note Your Credentials
|
|
131
|
+
|
|
132
|
+
In the **Settings** tab:
|
|
133
|
+
- **Domain**: `your-tenant.auth0.com` (or custom domain)
|
|
134
|
+
- **Client ID**: `a1b2c3d4e5f6g7h8i9j0k1l2`
|
|
135
|
+
- **Client Secret**: `A1B2C3D4E5...` (click "Show" to reveal)
|
|
136
|
+
|
|
137
|
+
### 4. Configure Connections (Optional)
|
|
138
|
+
|
|
139
|
+
Enable identity providers in **Authentication** > **Social** or **Enterprise**:
|
|
140
|
+
- Google
|
|
141
|
+
- Facebook
|
|
142
|
+
- GitHub
|
|
143
|
+
- Microsoft
|
|
144
|
+
- SAML
|
|
145
|
+
- Active Directory
|
|
146
|
+
- And many more...
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Routes
|
|
151
|
+
|
|
152
|
+
```ruby
|
|
153
|
+
# Auth0 OAuth
|
|
154
|
+
get "auth0", to: "auth0#create", as: :auth0
|
|
155
|
+
get "auth0/callback", to: "auth0#callback", as: :auth0_callback
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Available Routes**:
|
|
159
|
+
- `GET /oauth/auth0` → Initiates OAuth flow
|
|
160
|
+
- `GET /oauth/auth0/callback` → Handles OAuth callback
|
|
161
|
+
|
|
162
|
+
**Named Routes**:
|
|
163
|
+
- `oauth_auth0_path` → `/oauth/auth0`
|
|
164
|
+
- `oauth_auth0_callback_path` → `/oauth/auth0/callback`
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Auth0 Domains
|
|
169
|
+
|
|
170
|
+
### Tenant Domains
|
|
171
|
+
|
|
172
|
+
Auth0 provides different domain formats:
|
|
173
|
+
|
|
174
|
+
| Domain Type | Format | Example |
|
|
175
|
+
|-------------|--------|---------|
|
|
176
|
+
| US Tenant | `{tenant}.auth0.com` | `myapp.auth0.com` |
|
|
177
|
+
| EU Tenant | `{tenant}.eu.auth0.com` | `myapp.eu.auth0.com` |
|
|
178
|
+
| AU Tenant | `{tenant}.au.auth0.com` | `myapp.au.auth0.com` |
|
|
179
|
+
| Custom Domain | Your own domain | `auth.yourdomain.com` |
|
|
180
|
+
|
|
181
|
+
### Custom Domains
|
|
182
|
+
|
|
183
|
+
For production, you can configure a custom domain:
|
|
184
|
+
1. Go to **Branding** > **Custom Domains**
|
|
185
|
+
2. Follow setup instructions
|
|
186
|
+
3. Update `AUTH0_DOMAIN` to your custom domain
|
|
187
|
+
|
|
188
|
+
Benefits:
|
|
189
|
+
- Consistent branding
|
|
190
|
+
- First-party cookies
|
|
191
|
+
- Better user experience
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Additional Scopes (Optional)
|
|
196
|
+
|
|
197
|
+
### API Access
|
|
198
|
+
|
|
199
|
+
To call your own API protected by Auth0:
|
|
200
|
+
|
|
201
|
+
```ruby
|
|
202
|
+
config.oauth_providers = {
|
|
203
|
+
auth0: {
|
|
204
|
+
# ... other config
|
|
205
|
+
audience: "https://yourapi.com/api",
|
|
206
|
+
scope: "openid email profile read:data write:data"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
The `audience` parameter ensures the access token is valid for your API.
|
|
212
|
+
|
|
213
|
+
### Offline Access
|
|
214
|
+
|
|
215
|
+
For refresh tokens:
|
|
216
|
+
|
|
217
|
+
```ruby
|
|
218
|
+
scope: "openid email profile offline_access"
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
This allows you to get a refresh token to obtain new access tokens.
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Auth0 Management API
|
|
226
|
+
|
|
227
|
+
After authentication, you can call the Auth0 Management API for advanced user management:
|
|
228
|
+
|
|
229
|
+
### Get User Details
|
|
230
|
+
|
|
231
|
+
```ruby
|
|
232
|
+
GET https://your-tenant.auth0.com/api/v2/users/{user_id}
|
|
233
|
+
Authorization: Bearer {management_api_token}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**Note**: Requires a Management API token (different from user access token).
|
|
237
|
+
|
|
238
|
+
### Update User Metadata
|
|
239
|
+
|
|
240
|
+
```ruby
|
|
241
|
+
PATCH https://your-tenant.auth0.com/api/v2/users/{user_id}
|
|
242
|
+
Authorization: Bearer {management_api_token}
|
|
243
|
+
Content-Type: application/json
|
|
244
|
+
|
|
245
|
+
{
|
|
246
|
+
"user_metadata": {
|
|
247
|
+
"preference": "dark_mode"
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## Official Documentation
|
|
255
|
+
|
|
256
|
+
1. **Auth0 OAuth 2.0 Guide**
|
|
257
|
+
https://auth0.com/docs/authenticate/protocols/oauth
|
|
258
|
+
|
|
259
|
+
2. **Auth0 Authorization Code Flow**
|
|
260
|
+
https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow
|
|
261
|
+
|
|
262
|
+
3. **Auth0 Scopes**
|
|
263
|
+
https://auth0.com/docs/get-started/apis/scopes
|
|
264
|
+
|
|
265
|
+
4. **Auth0 Management API**
|
|
266
|
+
https://auth0.com/docs/api/management/v2
|
|
267
|
+
|
|
268
|
+
5. **Auth0 Custom Domains**
|
|
269
|
+
https://auth0.com/docs/customize/custom-domains
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Advanced Features
|
|
274
|
+
|
|
275
|
+
### Social Connections
|
|
276
|
+
|
|
277
|
+
Auth0 allows you to enable multiple social providers without additional integration:
|
|
278
|
+
|
|
279
|
+
**Available Providers**:
|
|
280
|
+
- Google
|
|
281
|
+
- Facebook
|
|
282
|
+
- GitHub
|
|
283
|
+
- Microsoft
|
|
284
|
+
- Twitter
|
|
285
|
+
- LinkedIn
|
|
286
|
+
- And 30+ more...
|
|
287
|
+
|
|
288
|
+
Users see a unified login screen and can choose their preferred provider.
|
|
289
|
+
|
|
290
|
+
### Enterprise Connections
|
|
291
|
+
|
|
292
|
+
For B2B applications:
|
|
293
|
+
- **SAML**: Integrate with enterprise identity providers
|
|
294
|
+
- **Active Directory/LDAP**: Connect to on-premise directories
|
|
295
|
+
- **Azure AD**: Microsoft enterprise authentication
|
|
296
|
+
- **OIDC**: Any OpenID Connect provider
|
|
297
|
+
|
|
298
|
+
### Multi-Factor Authentication (MFA)
|
|
299
|
+
|
|
300
|
+
Enable MFA in Auth0 Dashboard:
|
|
301
|
+
1. Go to **Security** > **Multi-factor Auth**
|
|
302
|
+
2. Enable factors (SMS, authenticator app, email)
|
|
303
|
+
3. Configure policies (always on, adaptive, optional)
|
|
304
|
+
|
|
305
|
+
### Custom Login Pages
|
|
306
|
+
|
|
307
|
+
Customize the login experience:
|
|
308
|
+
1. Go to **Branding** > **Universal Login**
|
|
309
|
+
2. Choose template or customize HTML/CSS
|
|
310
|
+
3. Match your brand identity
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## Troubleshooting
|
|
315
|
+
|
|
316
|
+
### "callback URL mismatch"
|
|
317
|
+
|
|
318
|
+
**Solution**: Ensure the callback URL in Auth0 Application Settings exactly matches:
|
|
319
|
+
```
|
|
320
|
+
https://yourdomain.com/oauth/auth0/callback
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
Auth0 is strict about trailing slashes and protocols.
|
|
324
|
+
|
|
325
|
+
### "invalid_grant"
|
|
326
|
+
|
|
327
|
+
**Solution**: The authorization code has expired or been used. Codes expire after 10 minutes. Ask user to try again.
|
|
328
|
+
|
|
329
|
+
### "unauthorized_client"
|
|
330
|
+
|
|
331
|
+
**Solution**:
|
|
332
|
+
- Check that grant type is enabled in Auth0 Application settings
|
|
333
|
+
- Ensure Application Type is "Regular Web Application"
|
|
334
|
+
|
|
335
|
+
### "access_denied"
|
|
336
|
+
|
|
337
|
+
**Solution**: User declined consent or doesn't have access. This is normal user behavior.
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## Security Considerations
|
|
342
|
+
|
|
343
|
+
### Token Expiration
|
|
344
|
+
|
|
345
|
+
Auth0 access tokens expire by default:
|
|
346
|
+
- **Access Token**: 24 hours (configurable)
|
|
347
|
+
- **ID Token**: Used for authentication only
|
|
348
|
+
- **Refresh Token**: Use `offline_access` scope
|
|
349
|
+
|
|
350
|
+
### Token Storage
|
|
351
|
+
|
|
352
|
+
The implementation stores the access token:
|
|
353
|
+
|
|
354
|
+
```ruby
|
|
355
|
+
user.access_token = token_data[:access_token]
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
**Recommendations**:
|
|
359
|
+
1. Encrypt the `access_token` column
|
|
360
|
+
2. Store `refresh_token` if using `offline_access`
|
|
361
|
+
3. Implement token refresh logic before expiration
|
|
362
|
+
|
|
363
|
+
### State Parameter
|
|
364
|
+
|
|
365
|
+
The implementation uses CSRF protection via state parameter:
|
|
366
|
+
|
|
367
|
+
```ruby
|
|
368
|
+
state = SecureRandom.hex(16)
|
|
369
|
+
session[:oauth_state] = state
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
This prevents cross-site request forgery attacks.
|
|
373
|
+
|
|
374
|
+
---
|
|
375
|
+
|
|
376
|
+
## Migration from Other Providers
|
|
377
|
+
|
|
378
|
+
Auth0 can help migrate users from:
|
|
379
|
+
- Custom database authentication
|
|
380
|
+
- Other identity providers
|
|
381
|
+
- Social logins
|
|
382
|
+
|
|
383
|
+
This allows gradual migration without forcing password resets.
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
**Last Updated**: October 15, 2025
|