hanko-rails 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f88c528ee17c1ca2a5c9fe5f220647fabbaab95f4d45be435fd685ad46f64fff
4
- data.tar.gz: 31ddfb033770159e3f92178cbb4333df5cdf7c8fc816f792129016bb7c4587b4
3
+ metadata.gz: c06034c2f3144758ec9276ba4de655e373e05cf0f43c19cfc4d4e12f9adb9fcf
4
+ data.tar.gz: b464d85f4d3378930e573296099af1f6602f11f8821e7eb05b72a73b71b3b24d
5
5
  SHA512:
6
- metadata.gz: 2b8bf26bd7ad716c76a3ff132e52e3cfcf925f699f139a9624aab7608aa4d7d4a6fe218da95836943155c0271fc5c08183a12d4c405cb889405e619a5ccde8b6
7
- data.tar.gz: a348e88853512e7d55b9988ce300e4059815c93a08c40daaf4a8b30b578ab7cb8e217d7240c564d9d4bf61d0c7d889e9d85f66debdeece0b75fd444fc4332501
6
+ metadata.gz: 7092b66e836e68f7f50d618e8513bd78daeee2920b260637d7e17d7b8f87fd764af29260d96e3903c60defdd309d7e2802277ca5c34d11e098bcd1e64d33f286
7
+ data.tar.gz: c2b83f34863b56658cb974f8aec454f951564a012f82859224024b69019958bc497c55fa0a179b2045a75df338267fdadbcf7dd751d880ad93c054195b282fc5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Fernando Ruiz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # hanko-rails
2
+
3
+ [![CI](https://github.com/fruizg0302/hanko-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/fruizg0302/hanko-ruby/actions)
4
+ [![Gem Version](https://badge.fury.io/rb/hanko-rails.svg)](https://rubygems.org/gems/hanko-rails)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ Rails integration for the [Hanko](https://www.hanko.io/) authentication platform. Provides Rack middleware for automatic session verification, controller helpers, an install generator, and test helpers.
8
+
9
+ > **Using Ruby without Rails?** See [hanko-ruby](https://rubygems.org/gems/hanko-ruby) for the framework-agnostic SDK.
10
+
11
+ ## Installation
12
+
13
+ ```ruby
14
+ # Gemfile
15
+ gem 'hanko-rails' # pulls in hanko-ruby automatically
16
+ ```
17
+
18
+ ```sh
19
+ bundle install
20
+ ```
21
+
22
+ ## Setup
23
+
24
+ Generate the initializer:
25
+
26
+ ```sh
27
+ bin/rails generate hanko:install
28
+ ```
29
+
30
+ This creates `config/initializers/hanko.rb`:
31
+
32
+ ```ruby
33
+ Hanko.configure do |config|
34
+ config.api_url = ENV.fetch('HANKO_API_URL', 'https://your-hanko-instance.hanko.io')
35
+ # config.api_key = ENV.fetch('HANKO_API_KEY', nil)
36
+ end
37
+
38
+ Hanko::Rails.configure do |config|
39
+ # config.cookie_name = 'hanko'
40
+ # config.exclude_paths = ['/healthz', '/up']
41
+ # config.jwks_cache_ttl = 3600
42
+ end
43
+ ```
44
+
45
+ ## Middleware
46
+
47
+ `Hanko::Rails::Middleware` is automatically inserted into the Rack stack by the engine. It:
48
+
49
+ 1. Extracts tokens from the `hanko` cookie or `Authorization: Bearer` header
50
+ 2. Verifies the JWT against the JWKS endpoint
51
+ 3. Sets `request.env['hanko.session']` with the decoded payload
52
+
53
+ Configure which paths to skip:
54
+
55
+ ```ruby
56
+ Hanko::Rails.configure do |config|
57
+ config.exclude_paths = ['/healthz', '/up', '/assets']
58
+ end
59
+ ```
60
+
61
+ ## Authentication Concern
62
+
63
+ Include `Hanko::Rails::Authentication` in your controllers:
64
+
65
+ ```ruby
66
+ class ApplicationController < ActionController::Base
67
+ include Hanko::Rails::Authentication
68
+
69
+ before_action :authenticate_hanko_user!
70
+ end
71
+ ```
72
+
73
+ ### Available helpers
74
+
75
+ | Helper | Returns |
76
+ |--------|---------|
77
+ | `hanko_session` | Decoded JWT payload hash, or `nil` |
78
+ | `hanko_user_id` | The `sub` claim (user UUID), or `nil` |
79
+ | `hanko_authenticated?` | `true` if a valid session exists |
80
+ | `current_hanko_user` | Alias for `hanko_user_id` |
81
+ | `authenticate_hanko_user!` | Redirects (HTML) or returns 401 (JSON) if unauthenticated |
82
+
83
+ All helpers except `authenticate_hanko_user!` are also available in views.
84
+
85
+ ## Using with your User model
86
+
87
+ ```ruby
88
+ class ApplicationController < ActionController::Base
89
+ include Hanko::Rails::Authentication
90
+
91
+ def current_user
92
+ @current_user ||= User.find_by(hanko_id: hanko_user_id) if hanko_authenticated?
93
+ end
94
+ helper_method :current_user
95
+ end
96
+ ```
97
+
98
+ ## Testing
99
+
100
+ The test helper is **opt-in** — require it explicitly:
101
+
102
+ ```ruby
103
+ require 'hanko/rails/test_helper'
104
+ ```
105
+
106
+ ### Setup with RSpec
107
+
108
+ ```ruby
109
+ # spec/support/hanko.rb
110
+ require 'hanko/rails/test_helper'
111
+
112
+ RSpec.configure do |config|
113
+ config.include Hanko::Rails::TestHelper, type: :request
114
+ end
115
+ ```
116
+
117
+ ### Usage
118
+
119
+ ```ruby
120
+ RSpec.describe 'Dashboard', type: :request do
121
+ it 'requires authentication' do
122
+ get '/dashboard'
123
+ expect(response).to have_http_status(:unauthorized)
124
+ end
125
+
126
+ it 'shows dashboard for authenticated user' do
127
+ sign_in_as_hanko_user('user-uuid')
128
+ get '/dashboard'
129
+ expect(response).to have_http_status(:ok)
130
+ end
131
+
132
+ it 'handles sign out' do
133
+ sign_in_as_hanko_user('user-uuid')
134
+ sign_out_hanko_user
135
+ get '/dashboard'
136
+ expect(response).to have_http_status(:unauthorized)
137
+ end
138
+ end
139
+ ```
140
+
141
+ ## Configuration Options
142
+
143
+ | Option | Default | Description |
144
+ |--------|---------|-------------|
145
+ | `cookie_name` | `'hanko'` | Name of the cookie holding the Hanko JWT |
146
+ | `jwks_cache_ttl` | `3600` | JWKS cache lifetime in seconds |
147
+ | `exclude_paths` | `[]` | Request path prefixes that skip verification |
148
+
149
+ ## Requirements
150
+
151
+ - Ruby >= 3.1
152
+ - Rails >= 7.0
153
+
154
+ ## Contributing
155
+
156
+ 1. Fork the repository
157
+ 2. Create your feature branch (`git checkout -b feature/my-feature`)
158
+ 3. Write tests for your changes
159
+ 4. Ensure all tests pass: `bundle exec rspec`
160
+ 5. Ensure linting passes: `bundle exec rubocop`
161
+ 6. Commit your changes (`git commit -m 'Add my feature'`)
162
+ 7. Push to the branch (`git push origin feature/my-feature`)
163
+ 8. Open a Pull Request
164
+
165
+ ## License
166
+
167
+ Released under the [MIT License](LICENSE.txt).
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Hanko
4
4
  module Rails
5
- VERSION = '0.1.4'
5
+ VERSION = '0.1.5'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanko-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Ruiz
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.1.4
18
+ version: 0.1.5
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.1.4
25
+ version: 0.1.5
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: railties
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -51,6 +51,8 @@ executables: []
51
51
  extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
+ - LICENSE.txt
55
+ - README.md
54
56
  - lib/hanko-rails.rb
55
57
  - lib/hanko/rails/authentication.rb
56
58
  - lib/hanko/rails/configuration.rb
@@ -67,6 +69,8 @@ metadata:
67
69
  homepage_uri: https://github.com/fruizg0302/hanko-ruby
68
70
  source_code_uri: https://github.com/fruizg0302/hanko-ruby/tree/main/hanko-rails
69
71
  changelog_uri: https://github.com/fruizg0302/hanko-ruby/blob/main/CHANGELOG.md
72
+ bug_tracker_uri: https://github.com/fruizg0302/hanko-ruby/issues
73
+ documentation_uri: https://rubydoc.info/gems/hanko-rails
70
74
  rubygems_mfa_required: 'true'
71
75
  rdoc_options: []
72
76
  require_paths: