better_auth 0.1.1 → 0.3.0

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.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/README.md +110 -18
  4. data/lib/better_auth/adapters/base.rb +49 -0
  5. data/lib/better_auth/adapters/internal_adapter.rb +589 -0
  6. data/lib/better_auth/adapters/memory.rb +235 -0
  7. data/lib/better_auth/adapters/mongodb.rb +9 -0
  8. data/lib/better_auth/adapters/mssql.rb +42 -0
  9. data/lib/better_auth/adapters/mysql.rb +33 -0
  10. data/lib/better_auth/adapters/postgres.rb +17 -0
  11. data/lib/better_auth/adapters/sql.rb +441 -0
  12. data/lib/better_auth/adapters/sqlite.rb +20 -0
  13. data/lib/better_auth/api.rb +226 -0
  14. data/lib/better_auth/api_error.rb +53 -0
  15. data/lib/better_auth/auth.rb +42 -0
  16. data/lib/better_auth/configuration.rb +399 -0
  17. data/lib/better_auth/context.rb +211 -0
  18. data/lib/better_auth/cookies.rb +278 -0
  19. data/lib/better_auth/core.rb +37 -1
  20. data/lib/better_auth/crypto/jwe.rb +76 -0
  21. data/lib/better_auth/crypto.rb +191 -0
  22. data/lib/better_auth/database_hooks.rb +114 -0
  23. data/lib/better_auth/endpoint.rb +326 -0
  24. data/lib/better_auth/error.rb +52 -0
  25. data/lib/better_auth/middleware/origin_check.rb +128 -0
  26. data/lib/better_auth/password.rb +120 -0
  27. data/lib/better_auth/plugin.rb +142 -0
  28. data/lib/better_auth/plugin_context.rb +16 -0
  29. data/lib/better_auth/plugin_registry.rb +67 -0
  30. data/lib/better_auth/plugins/access.rb +87 -0
  31. data/lib/better_auth/plugins/additional_fields.rb +29 -0
  32. data/lib/better_auth/plugins/admin/schema.rb +28 -0
  33. data/lib/better_auth/plugins/admin.rb +518 -0
  34. data/lib/better_auth/plugins/anonymous.rb +198 -0
  35. data/lib/better_auth/plugins/api_key.rb +16 -0
  36. data/lib/better_auth/plugins/bearer.rb +128 -0
  37. data/lib/better_auth/plugins/captcha.rb +159 -0
  38. data/lib/better_auth/plugins/custom_session.rb +84 -0
  39. data/lib/better_auth/plugins/device_authorization.rb +302 -0
  40. data/lib/better_auth/plugins/email_otp.rb +536 -0
  41. data/lib/better_auth/plugins/expo.rb +88 -0
  42. data/lib/better_auth/plugins/generic_oauth.rb +780 -0
  43. data/lib/better_auth/plugins/have_i_been_pwned.rb +94 -0
  44. data/lib/better_auth/plugins/jwt.rb +482 -0
  45. data/lib/better_auth/plugins/last_login_method.rb +92 -0
  46. data/lib/better_auth/plugins/magic_link.rb +181 -0
  47. data/lib/better_auth/plugins/mcp.rb +342 -0
  48. data/lib/better_auth/plugins/multi_session.rb +173 -0
  49. data/lib/better_auth/plugins/oauth_protocol.rb +694 -0
  50. data/lib/better_auth/plugins/oauth_provider.rb +16 -0
  51. data/lib/better_auth/plugins/oauth_proxy.rb +257 -0
  52. data/lib/better_auth/plugins/oidc_provider.rb +597 -0
  53. data/lib/better_auth/plugins/one_tap.rb +154 -0
  54. data/lib/better_auth/plugins/one_time_token.rb +106 -0
  55. data/lib/better_auth/plugins/open_api.rb +489 -0
  56. data/lib/better_auth/plugins/organization/schema.rb +106 -0
  57. data/lib/better_auth/plugins/organization.rb +995 -0
  58. data/lib/better_auth/plugins/passkey.rb +16 -0
  59. data/lib/better_auth/plugins/phone_number.rb +321 -0
  60. data/lib/better_auth/plugins/scim.rb +16 -0
  61. data/lib/better_auth/plugins/siwe.rb +242 -0
  62. data/lib/better_auth/plugins/sso.rb +16 -0
  63. data/lib/better_auth/plugins/stripe.rb +16 -0
  64. data/lib/better_auth/plugins/two_factor.rb +514 -0
  65. data/lib/better_auth/plugins/username.rb +278 -0
  66. data/lib/better_auth/plugins.rb +46 -0
  67. data/lib/better_auth/rate_limiter.rb +232 -0
  68. data/lib/better_auth/request_ip.rb +70 -0
  69. data/lib/better_auth/router.rb +378 -0
  70. data/lib/better_auth/routes/account.rb +211 -0
  71. data/lib/better_auth/routes/email_verification.rb +111 -0
  72. data/lib/better_auth/routes/error.rb +102 -0
  73. data/lib/better_auth/routes/ok.rb +15 -0
  74. data/lib/better_auth/routes/password.rb +183 -0
  75. data/lib/better_auth/routes/session.rb +160 -0
  76. data/lib/better_auth/routes/sign_in.rb +90 -0
  77. data/lib/better_auth/routes/sign_out.rb +15 -0
  78. data/lib/better_auth/routes/sign_up.rb +196 -0
  79. data/lib/better_auth/routes/social.rb +367 -0
  80. data/lib/better_auth/routes/user.rb +205 -0
  81. data/lib/better_auth/schema/sql.rb +202 -0
  82. data/lib/better_auth/schema.rb +291 -0
  83. data/lib/better_auth/session.rb +122 -0
  84. data/lib/better_auth/session_store.rb +91 -0
  85. data/lib/better_auth/social_providers/apple.rb +91 -0
  86. data/lib/better_auth/social_providers/atlassian.rb +32 -0
  87. data/lib/better_auth/social_providers/base.rb +325 -0
  88. data/lib/better_auth/social_providers/cognito.rb +32 -0
  89. data/lib/better_auth/social_providers/discord.rb +81 -0
  90. data/lib/better_auth/social_providers/dropbox.rb +33 -0
  91. data/lib/better_auth/social_providers/facebook.rb +35 -0
  92. data/lib/better_auth/social_providers/figma.rb +31 -0
  93. data/lib/better_auth/social_providers/github.rb +74 -0
  94. data/lib/better_auth/social_providers/gitlab.rb +67 -0
  95. data/lib/better_auth/social_providers/google.rb +90 -0
  96. data/lib/better_auth/social_providers/huggingface.rb +31 -0
  97. data/lib/better_auth/social_providers/kakao.rb +32 -0
  98. data/lib/better_auth/social_providers/kick.rb +32 -0
  99. data/lib/better_auth/social_providers/line.rb +33 -0
  100. data/lib/better_auth/social_providers/linear.rb +44 -0
  101. data/lib/better_auth/social_providers/linkedin.rb +30 -0
  102. data/lib/better_auth/social_providers/microsoft_entra_id.rb +137 -0
  103. data/lib/better_auth/social_providers/naver.rb +31 -0
  104. data/lib/better_auth/social_providers/notion.rb +33 -0
  105. data/lib/better_auth/social_providers/paybin.rb +31 -0
  106. data/lib/better_auth/social_providers/paypal.rb +36 -0
  107. data/lib/better_auth/social_providers/polar.rb +31 -0
  108. data/lib/better_auth/social_providers/railway.rb +49 -0
  109. data/lib/better_auth/social_providers/reddit.rb +32 -0
  110. data/lib/better_auth/social_providers/roblox.rb +31 -0
  111. data/lib/better_auth/social_providers/salesforce.rb +38 -0
  112. data/lib/better_auth/social_providers/slack.rb +30 -0
  113. data/lib/better_auth/social_providers/spotify.rb +31 -0
  114. data/lib/better_auth/social_providers/tiktok.rb +35 -0
  115. data/lib/better_auth/social_providers/twitch.rb +39 -0
  116. data/lib/better_auth/social_providers/twitter.rb +32 -0
  117. data/lib/better_auth/social_providers/vercel.rb +47 -0
  118. data/lib/better_auth/social_providers/vk.rb +34 -0
  119. data/lib/better_auth/social_providers/wechat.rb +104 -0
  120. data/lib/better_auth/social_providers/zoom.rb +31 -0
  121. data/lib/better_auth/social_providers.rb +38 -0
  122. data/lib/better_auth/version.rb +1 -1
  123. data/lib/better_auth.rb +86 -2
  124. metadata +233 -21
  125. data/.ruby-version +0 -1
  126. data/.standard.yml +0 -12
  127. data/.vscode/settings.json +0 -22
  128. data/AGENTS.md +0 -50
  129. data/CLAUDE.md +0 -1
  130. data/CODE_OF_CONDUCT.md +0 -173
  131. data/CONTRIBUTING.md +0 -187
  132. data/Gemfile +0 -12
  133. data/Makefile +0 -207
  134. data/Rakefile +0 -25
  135. data/SECURITY.md +0 -28
  136. data/docker-compose.yml +0 -63
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2ba3cc27f9b1ebc6cb35de7a95a10351c30f5523de796c82b7c90773d663381
4
- data.tar.gz: 81b03e1d625d242adc6255806b7651cebee65f59179110aae7df85b7beab426f
3
+ metadata.gz: df93cdae06059d52fa2c3d35c5b173aba9025d5ac46bda0b93a7a8abc5045f40
4
+ data.tar.gz: adec802dade2610da15329266c91dcd46aecb8642165c29e364ce7db2829d217
5
5
  SHA512:
6
- metadata.gz: 61a29dc835cd5758628b358153888cc78eb721795cd286e55210c920766129826d08b5bbdf2fe9a049df56b3d6a9d4bd8f33c82b067bde77c812c87738af94e2
7
- data.tar.gz: 18d543129a8577e9974ce0887db187e837ff2b9175cce97efd33a6afba615f1d34272fb193a0008694c63c998b12740ed6c2490ecb765ad9b24f131be389a250
6
+ metadata.gz: f46ac8a5cf79a859a417e2cbe60f000c290d014975fb3ce910c49b6c1cd455b2123e436a42a323dd530b38096a4ebc18a1f206c97f0ef6624378c9eb051d37e3
7
+ data.tar.gz: '0469ddcdcad97a7b1b58e3ddc0ef8d54c7469a1e0411546367f829291ab5664fc0b4685d460d8d328fe6ef67543908060d33eb961a638121930154ca31a4cfaf'
data/CHANGELOG.md CHANGED
@@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.0] - 2026-04-29
11
+
12
+ ### Added
13
+
14
+ - Added upstream-parity social provider support, including provider-specific authorization, token, profile, refresh, and revocation behavior for the expanded provider set.
15
+ - Added OAuth/OIDC protocol hardening for authorization, callback, discovery, metadata, token, and userinfo flows.
16
+ - Added upstream v1.6.9 parity coverage for schema generation, adapter behavior, plugin hooks, session handling, and account/user route edge cases.
17
+
18
+ ### Changed
19
+
20
+ - Extracted MongoDB adapter support behind the external `better_auth-mongo-adapter` shim while preserving compatibility for existing adapter configuration.
21
+ - Updated auth routes, router behavior, rate limiting, password and email-verification flows, and schema metadata to match upstream semantics more closely.
22
+
23
+ ### Fixed
24
+
25
+ - Fixed social provider edge cases, magic-link expiration behavior, adapter value coercion, and callback/session handling across Rack integrations.
26
+
27
+ ## [0.1.1] - 2026-03-22
28
+
29
+ ### Fixed
30
+
31
+ - Fixed gemspec files list to use `Dir.glob` instead of `git ls-files` for better CI compatibility
32
+
10
33
  ### Added
11
34
 
12
35
  - Initial project setup
data/README.md CHANGED
@@ -60,11 +60,96 @@ gem install better_auth
60
60
  ```ruby
61
61
  require 'better_auth'
62
62
 
63
- # Configure Better Auth
64
- BetterAuth.configure do |config|
65
- config.secret_key = ENV['BETTER_AUTH_SECRET']
66
- config.database_url = ENV['DATABASE_URL']
67
- end
63
+ auth = BetterAuth.auth(
64
+ secret: ENV.fetch("BETTER_AUTH_SECRET"),
65
+ database: :memory
66
+ )
67
+ ```
68
+
69
+ ### Password Hashing
70
+
71
+ Better Auth Ruby uses upstream-compatible `scrypt` password hashes by default through Ruby's `OpenSSL::KDF.scrypt`, so no extra password-hashing gem is required for the default setup.
72
+
73
+ ```ruby
74
+ auth = BetterAuth.auth(
75
+ secret: ENV.fetch("BETTER_AUTH_SECRET"),
76
+ password_hasher: :scrypt # default
77
+ )
78
+ ```
79
+
80
+ Applications that prefer Ruby's familiar BCrypt ecosystem can opt in by adding `gem "bcrypt"` and configuring:
81
+
82
+ ```ruby
83
+ auth = BetterAuth.auth(
84
+ secret: ENV.fetch("BETTER_AUTH_SECRET"),
85
+ password_hasher: :bcrypt
86
+ )
87
+ ```
88
+
89
+ Custom Better Auth-style password callbacks are still supported through `email_and_password[:password][:hash]` and `[:verify]`.
90
+
91
+ ### Database Adapters
92
+
93
+ The core gem ships framework-agnostic adapters for memory, PostgreSQL, MySQL, SQLite, and MSSQL. Driver gems are loaded only when their adapter is instantiated. MongoDB support lives in the external `better_auth-mongo-adapter` package so apps that do not use MongoDB do not install the Mongo driver.
94
+
95
+ ```ruby
96
+ auth = BetterAuth.auth(
97
+ secret: ENV.fetch("BETTER_AUTH_SECRET"),
98
+ database: BetterAuth::Adapters::SQLite.new(path: "storage/auth.sqlite3")
99
+ )
100
+ ```
101
+
102
+ ```ruby
103
+ require "better_auth/mongo_adapter"
104
+
105
+ auth = BetterAuth.auth(
106
+ secret: ENV.fetch("BETTER_AUTH_SECRET"),
107
+ database: BetterAuth::Adapters::MongoDB.new(
108
+ database: mongo_client.database,
109
+ client: mongo_client,
110
+ transaction: false
111
+ )
112
+ )
113
+ ```
114
+
115
+ ```ruby
116
+ auth = BetterAuth.auth(
117
+ secret: ENV.fetch("BETTER_AUTH_SECRET"),
118
+ database: BetterAuth::Adapters::MSSQL.new(url: ENV.fetch("DATABASE_URL"))
119
+ )
120
+ ```
121
+
122
+ ### Social Providers
123
+
124
+ ```ruby
125
+ require "better_auth"
126
+
127
+ auth = BetterAuth.auth(
128
+ secret: ENV.fetch("BETTER_AUTH_SECRET"),
129
+ social_providers: {
130
+ google: BetterAuth::SocialProviders.google(
131
+ client_id: ENV.fetch("GOOGLE_CLIENT_ID"),
132
+ client_secret: ENV.fetch("GOOGLE_CLIENT_SECRET")
133
+ ),
134
+ github: BetterAuth::SocialProviders.github(
135
+ client_id: ENV.fetch("GITHUB_CLIENT_ID"),
136
+ client_secret: ENV.fetch("GITHUB_CLIENT_SECRET")
137
+ )
138
+ }
139
+ )
140
+ ```
141
+
142
+ ### JavaScript Client
143
+
144
+ Ruby Better Auth exposes the same HTTP route surface. Frontend apps should use the upstream Better Auth JavaScript client and point it at the Ruby server:
145
+
146
+ ```ts
147
+ import { createAuthClient } from "better-auth/client";
148
+
149
+ export const authClient = createAuthClient({
150
+ baseURL: "http://localhost:3000",
151
+ basePath: "/api/auth",
152
+ });
68
153
  ```
69
154
 
70
155
  ### Rails Integration
@@ -72,7 +157,7 @@ end
72
157
  Add to your Gemfile:
73
158
 
74
159
  ```ruby
75
- gem 'better_auth', require: 'better_auth/rails'
160
+ gem "better_auth-rails"
76
161
  ```
77
162
 
78
163
  Then in your ApplicationController:
@@ -87,7 +172,7 @@ Now you have access to `current_user` and authentication methods:
87
172
 
88
173
  ```ruby
89
174
  class PostsController < ApplicationController
90
- before_action :authenticate_user!
175
+ before_action :require_authentication
91
176
 
92
177
  def index
93
178
  @posts = current_user.posts
@@ -97,6 +182,8 @@ end
97
182
 
98
183
  ## Development
99
184
 
185
+ Full documentation is being adapted in the root [`docs/`](/Users/sebastiansala/projects/better-auth/docs/README.md) app. Start with the Ruby-first installation, basic usage, Rack, Rails, PostgreSQL, and MySQL pages there; pages with a Ruby port warning still contain upstream TypeScript examples for reference.
186
+
100
187
  ### Quick Start
101
188
 
102
189
  ```bash
@@ -132,7 +219,7 @@ make test-coverage # Tests with coverage
132
219
  make ci # Full CI (lint + test)
133
220
 
134
221
  # Databases for testing
135
- make db-up # Start PostgreSQL, MySQL, Redis
222
+ make db-up # Start PostgreSQL, MySQL, MongoDB, MSSQL, Redis
136
223
  make db-down # Stop containers
137
224
  ```
138
225
 
@@ -183,10 +270,10 @@ git push origin feat/new-feature
183
270
 
184
271
  **Automatic Release (GitHub Actions):**
185
272
 
186
- Release is triggered on `push` to `main` when `lib/better_auth/version.rb` changes.
273
+ Release is triggered by package-prefixed tags so each gem can ship independently.
187
274
 
188
275
  ```bash
189
- # STEP 1: Update version in lib/better_auth/version.rb
276
+ # STEP 1: Update the target package version file
190
277
  # Example: VERSION = "0.1.1"
191
278
 
192
279
  # STEP 2: Commit and push to main
@@ -194,19 +281,24 @@ git add lib/better_auth/version.rb
194
281
  git commit -m "chore: bump version to 0.1.1"
195
282
  git push origin main
196
283
 
197
- # STEP 3: GitHub Actions automatically:
284
+ # STEP 3: Create the tag for the gem you want to publish
285
+ git tag better_auth-v0.1.1
286
+ git push origin better_auth-v0.1.1
287
+
288
+ # STEP 4: GitHub Actions automatically:
198
289
  # - Runs tests
199
290
  # - Builds the gem
200
291
  # - Publishes to RubyGems (if version is new)
201
- # - Creates and pushes git tag (v0.1.1)
202
292
  # - Creates GitHub Release
203
293
  ```
204
294
 
295
+ Use `better_auth-vX.Y.Z` for the core gem, `better_auth-rails-vX.Y.Z` for Rails, `better_auth-sinatra-vX.Y.Z` for Sinatra, and `better_auth-hanami-vX.Y.Z` for Hanami.
296
+
205
297
  **Required GitHub Configuration:**
206
298
 
207
- 1. Go to Settings Secrets and variables Actions
208
- 2. Add `RUBYGEMS_API_KEY` with your RubyGems API key
209
- 3. The workflow `.github/workflows/release.yml` does the rest
299
+ 1. In RubyGems, configure Trusted Publishing for each gem that should publish from CI.
300
+ 2. Use this repository and workflow file: `.github/workflows/release.yml`.
301
+ 3. The workflow exchanges GitHub's OIDC token for short-lived RubyGems credentials when the matching package tag is pushed.
210
302
 
211
303
  **Dry-run options:**
212
304
 
@@ -231,8 +323,8 @@ gem build better_auth.gemspec
231
323
  gem push better_auth-*.gem
232
324
 
233
325
  # 4. Create and push the tag
234
- git tag -a v0.1.1 -m "Release v0.1.1"
235
- git push origin --tags
326
+ git tag -a better_auth-v0.1.1 -m "Release better_auth v0.1.1"
327
+ git push origin better_auth-v0.1.1
236
328
  ```
237
329
 
238
330
  ### Project Structure
@@ -262,6 +354,6 @@ The gem is available as open source under the terms of the [MIT License](https:/
262
354
 
263
355
  ## Security
264
356
 
265
- If you discover a security vulnerability within Better Auth Ruby, please send an e-mail to [security@better-auth.com](mailto:security@better-auth.com).
357
+ If you discover a security vulnerability within Better Auth Ruby, please send an e-mail to [security@openparcel.dev](mailto:security@openparcel.dev).
266
358
 
267
359
  All reports will be promptly addressed, and you'll be credited accordingly.
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BetterAuth
4
+ module Adapters
5
+ class Base
6
+ attr_reader :options
7
+
8
+ def initialize(options)
9
+ @options = options
10
+ end
11
+
12
+ def create(**)
13
+ raise NotImplementedError
14
+ end
15
+
16
+ def find_one(**)
17
+ raise NotImplementedError
18
+ end
19
+
20
+ def find_many(**)
21
+ raise NotImplementedError
22
+ end
23
+
24
+ def update(**)
25
+ raise NotImplementedError
26
+ end
27
+
28
+ def update_many(**)
29
+ raise NotImplementedError
30
+ end
31
+
32
+ def delete(**)
33
+ raise NotImplementedError
34
+ end
35
+
36
+ def delete_many(**)
37
+ raise NotImplementedError
38
+ end
39
+
40
+ def count(**)
41
+ raise NotImplementedError
42
+ end
43
+
44
+ def transaction
45
+ yield self
46
+ end
47
+ end
48
+ end
49
+ end