clavis 0.7.1 → 0.7.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.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clavis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clayton Lengel-Zigich
@@ -158,6 +158,7 @@ extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
160
  - ".actrc"
161
+ - ".brakeman.ignore"
161
162
  - ".cursor/rules/ruby-gem.mdc"
162
163
  - ".gemignore"
163
164
  - ".rspec"
@@ -168,14 +169,12 @@ files:
168
169
  - LICENSE.txt
169
170
  - README.md
170
171
  - Rakefile
171
- - UPGRADE.md
172
172
  - app/assets/stylesheets/clavis.css
173
173
  - app/controllers/clavis/auth_controller.rb
174
174
  - config/database.yml
175
175
  - config/routes.rb
176
176
  - docs/SECURITY.md
177
177
  - docs/TESTING.md
178
- - docs/integration.md
179
178
  - error_handling.md
180
179
  - file_structure.md
181
180
  - gemfiles/rails_80.gemfile
@@ -228,7 +227,6 @@ files:
228
227
  - log/development.log
229
228
  - log/test.log
230
229
  - sig/clavis.rbs
231
- - testing_plan.md
232
230
  homepage: https://github.com/clayton/clavis
233
231
  licenses:
234
232
  - MIT
data/UPGRADE.md DELETED
@@ -1,57 +0,0 @@
1
- # Clavis Upgrade Guide
2
-
3
- ## Upgrading to 0.2.0 from 0.1.x
4
-
5
- Version 0.2.0 brings several important fixes and improvements to the Clavis gem, focusing on better documentation, improved compatibility with existing Rails applications, and bug fixes for various integration issues.
6
-
7
- ### Key Changes
8
-
9
- 1. **Module Alias Consistency**:
10
- - The module `Clavis::Models::OauthAuthenticatable` is now properly aliased to `Clavis::Models::Concerns::OauthAuthenticatable`
11
- - This means either reference can be used in your application code: `include Clavis::Models::OauthAuthenticatable` or `include Clavis::Models::Concerns::OauthAuthenticatable`
12
-
13
- 2. **View Helper Integration**:
14
- - Improved automatic inclusion of view helpers in Rails applications
15
- - Fixed issues with helper availability in `ApplicationHelper`
16
- - View helpers like `clavis_oauth_button` should now work out of the box
17
-
18
- 3. **Installation Generator Improvements**:
19
- - Updated the `clavis:install` generator to properly handle the creation of OAuth identity tables
20
- - Fixed issues with duplicate migrations
21
- - Added better support for integrating with existing User models
22
-
23
- 4. **Documentation Updates**:
24
- - Added comprehensive guide for integrating with existing authentication systems
25
- - Corrected inconsistencies between code examples and actual implementations
26
- - Updated installation and configuration guidance
27
-
28
- ### Migration Steps
29
-
30
- **For most users, no changes are required**. The improvements in 0.2.0 are backward compatible.
31
-
32
- If you encountered any of the specific issues addressed in this release, upgrade to 0.2.0 and follow these steps:
33
-
34
- 1. Update your Gemfile:
35
- ```ruby
36
- gem 'clavis', '~> 0.2.0'
37
- ```
38
-
39
- 2. Run bundle install:
40
- ```bash
41
- bundle install
42
- ```
43
-
44
- 3. If you've manually implemented workarounds for any of the fixed issues, you can now remove them.
45
-
46
- 4. If you're integrating with an existing application, refer to the new integration guide at `/docs/integration.md` for detailed instructions.
47
-
48
- ### New Documentation
49
-
50
- - `docs/integration.md` - Guide for integrating Clavis with existing authentication systems
51
- - Updated README with clearer instructions and example code
52
- - Improved error handling documentation
53
-
54
- ### Known Issues
55
-
56
- - Rails 7.1+ and Ruby 3.4+ compatibility testing is ongoing
57
- - Full test suite coverage requires a Rails environment for some specs
data/docs/integration.md DELETED
@@ -1,272 +0,0 @@
1
- # Integrating Clavis with Existing Applications
2
-
3
- This guide covers how to integrate Clavis with your existing Ruby on Rails application, particularly if you already have an authentication system in place.
4
-
5
- ## Table of Contents
6
-
7
- 1. [Overview](#overview)
8
- 2. [Database Setup](#database-setup)
9
- 3. [User Model Integration](#user-model-integration)
10
- 4. [Controller Integration](#controller-integration)
11
- 5. [View Integration](#view-integration)
12
- 6. [Route Configuration](#route-configuration)
13
- 7. [Working with Multiple Authentication Methods](#working-with-multiple-authentication-methods)
14
- 8. [Troubleshooting](#troubleshooting)
15
-
16
- ## Overview
17
-
18
- Clavis is designed to work alongside your existing authentication system, providing OAuth/OIDC capabilities without replacing your current setup. This guide assumes you have an existing application with:
19
-
20
- - A `User` model
21
- - Some form of authentication (e.g., `has_secure_password`, Devise, etc.)
22
- - Session management
23
-
24
- ## Database Setup
25
-
26
- Clavis stores OAuth identities in a separate table with a polymorphic relationship to your user model.
27
-
28
- 1. **Run the installation generator**:
29
-
30
- ```bash
31
- rails generate clavis:install
32
- ```
33
-
34
- 2. **Review and run the migration**:
35
-
36
- ```bash
37
- rails db:migrate
38
- ```
39
-
40
- This creates a `clavis_oauth_identities` table with:
41
-
42
- ```ruby
43
- create_table :clavis_oauth_identities do |t|
44
- t.references :user, polymorphic: true, null: false, index: true
45
- t.string :provider, null: false
46
- t.string :uid, null: false
47
- t.json :auth_data
48
- t.string :token
49
- t.string :refresh_token
50
- t.datetime :expires_at
51
- t.timestamps
52
-
53
- t.index [:provider, :uid], unique: true
54
- end
55
- ```
56
-
57
- ## User Model Integration
58
-
59
- Include the `OauthAuthenticatable` concern in your User model:
60
-
61
- ```ruby
62
- # app/models/user.rb
63
- class User < ApplicationRecord
64
- include Clavis::Models::OauthAuthenticatable
65
-
66
- # Your existing authentication code (e.g., has_secure_password)
67
-
68
- # Optional: Customize how users are created/found from OAuth data
69
- def self.find_for_oauth(auth_hash)
70
- super do |user, auth|
71
- # Set additional attributes based on the OAuth data
72
- user.name = auth[:info][:name] if user.respond_to?(:name=)
73
- user.username = auth[:info][:nickname] if user.respond_to?(:username=)
74
- # You can access profile image with auth[:info][:image]
75
- # You can access email with auth[:info][:email]
76
- end
77
- end
78
- end
79
- ```
80
-
81
- ## Controller Integration
82
-
83
- You have a few options for controller integration:
84
-
85
- ### Option 1: Use your existing authentication controller
86
-
87
- ```ruby
88
- # app/controllers/sessions_controller.rb
89
- class SessionsController < ApplicationController
90
- include Clavis::Controllers::Concerns::Authentication
91
-
92
- # Your existing login/logout actions...
93
-
94
- # Add OAuth callback handler
95
- def oauth_callback
96
- auth_hash = process_callback(params[:provider])
97
-
98
- # Find or create a user with the OAuth data
99
- @user = User.find_for_oauth(auth_hash)
100
-
101
- # Sign in the user (using your existing authentication system)
102
- session[:user_id] = @user.id
103
-
104
- redirect_to root_path, notice: "Signed in successfully!"
105
- rescue Clavis::AuthenticationError => e
106
- redirect_to login_path, alert: "Authentication failed: #{e.message}"
107
- end
108
-
109
- # Add OAuth authorization handler
110
- def oauth_authorize
111
- redirect_to auth_url(params[:provider])
112
- end
113
- end
114
- ```
115
-
116
- ### Option 2: Generate a dedicated OAuth controller
117
-
118
- ```bash
119
- rails generate clavis:controller Auth
120
- ```
121
-
122
- This creates:
123
- - `app/controllers/auth_controller.rb` with OAuth methods
124
- - Views for login/etc.
125
- - Routes for the OAuth flow
126
-
127
- ## View Integration
128
-
129
- ### Add OAuth buttons to your login form:
130
-
131
- ```erb
132
- <%# app/views/sessions/new.html.erb %>
133
- <h1>Sign In</h1>
134
-
135
- <%# Your existing login form... %>
136
-
137
- <div class="oauth-buttons">
138
- <p>Or sign in with:</p>
139
- <%= clavis_oauth_button :google %>
140
- <%= clavis_oauth_button :github %>
141
- </div>
142
- ```
143
-
144
- ### Customize button appearance:
145
-
146
- ```erb
147
- <%= clavis_oauth_button :google, text: "Continue with Google", class: "my-custom-button" %>
148
- ```
149
-
150
- ## Route Configuration
151
-
152
- Add the necessary routes to your application:
153
-
154
- ```ruby
155
- # config/routes.rb
156
- Rails.application.routes.draw do
157
- # Your existing routes...
158
-
159
- # OAuth routes
160
- get '/auth/:provider', to: 'sessions#oauth_authorize', as: :auth
161
- get '/auth/:provider/callback', to: 'sessions#oauth_callback'
162
- end
163
- ```
164
-
165
- ## Working with Multiple Authentication Methods
166
-
167
- When a user signs in with OAuth, you'll need to decide how to handle users who might already have password-based accounts:
168
-
169
- ### Email Matching Strategy
170
-
171
- This is the default strategy in Clavis - when a user signs in with OAuth:
172
-
173
- 1. Clavis tries to find an existing `OauthIdentity` for the provider/uid
174
- 2. If not found, it looks for a user with a matching email address
175
- 3. If a user with matching email is found, it associates the OAuth identity with that user
176
- 4. If no user is found, it creates a new user and associates the OAuth identity
177
-
178
- ### Linking Accounts
179
-
180
- You might want to allow users to link multiple OAuth providers to their account:
181
-
182
- ```ruby
183
- # app/controllers/profiles_controller.rb
184
- def link_oauth
185
- # Store the user_id in the session
186
- session[:linking_user_id] = current_user.id
187
-
188
- # Redirect to the OAuth provider
189
- redirect_to auth_path(params[:provider])
190
- end
191
-
192
- # app/controllers/sessions_controller.rb
193
- def oauth_callback
194
- auth_hash = process_callback(params[:provider])
195
-
196
- # Check if we're linking an existing account
197
- if session[:linking_user_id].present?
198
- user = User.find(session[:linking_user_id])
199
- session.delete(:linking_user_id)
200
-
201
- # Find or create the identity
202
- identity = Clavis::OauthIdentity.find_or_initialize_by(
203
- provider: auth_hash[:provider],
204
- uid: auth_hash[:uid]
205
- )
206
-
207
- # Associate with the user
208
- identity.user = user
209
- identity.auth_data = auth_hash[:info]
210
- identity.token = auth_hash[:credentials][:token]
211
- identity.refresh_token = auth_hash[:credentials][:refresh_token]
212
- identity.expires_at = auth_hash[:credentials][:expires_at] ? Time.at(auth_hash[:credentials][:expires_at]) : nil
213
- identity.save!
214
-
215
- redirect_to edit_profile_path, notice: "Successfully linked #{params[:provider].capitalize} account"
216
- else
217
- # Normal login flow...
218
- end
219
- end
220
- ```
221
-
222
- ## Troubleshooting
223
-
224
- ### View Helper Issues
225
-
226
- If you're having trouble with the `clavis_oauth_button` helper, ensure your application helper includes Clavis's view helpers:
227
-
228
- ```ruby
229
- # app/helpers/application_helper.rb
230
- module ApplicationHelper
231
- include Clavis::ViewHelpers
232
- # ...
233
- end
234
- ```
235
-
236
- ### Database Issues
237
-
238
- If you see errors about the `clavis_oauth_identities` table, make sure you've run:
239
-
240
- ```bash
241
- rails db:migrate
242
- ```
243
-
244
- ### Session Issues
245
-
246
- If you're experiencing session-related issues:
247
-
248
- 1. Ensure you're not using `session.clear` which would remove Clavis's state parameters
249
- 2. Consider enabling session rotation in your Clavis configuration:
250
-
251
- ```ruby
252
- Clavis.configure do |config|
253
- config.rotate_session_after_login = true
254
- end
255
- ```
256
-
257
- ### Missing Routes
258
-
259
- If you see errors about missing routes for OAuth buttons, ensure you've added:
260
-
261
- ```ruby
262
- get '/auth/:provider', to: 'sessions#oauth_authorize', as: :auth
263
- get '/auth/:provider/callback', to: 'sessions#oauth_callback'
264
- ```
265
-
266
- ### Security Concerns
267
-
268
- For production environments, always ensure:
269
-
270
- 1. You're using HTTPS
271
- 2. Your OAuth provider credentials are properly secured (e.g., using Rails credentials)
272
- 3. You've configured allowed redirect hosts in Clavis configuration