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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/README.md +110 -18
- data/lib/better_auth/adapters/base.rb +49 -0
- data/lib/better_auth/adapters/internal_adapter.rb +589 -0
- data/lib/better_auth/adapters/memory.rb +235 -0
- data/lib/better_auth/adapters/mongodb.rb +9 -0
- data/lib/better_auth/adapters/mssql.rb +42 -0
- data/lib/better_auth/adapters/mysql.rb +33 -0
- data/lib/better_auth/adapters/postgres.rb +17 -0
- data/lib/better_auth/adapters/sql.rb +441 -0
- data/lib/better_auth/adapters/sqlite.rb +20 -0
- data/lib/better_auth/api.rb +226 -0
- data/lib/better_auth/api_error.rb +53 -0
- data/lib/better_auth/auth.rb +42 -0
- data/lib/better_auth/configuration.rb +399 -0
- data/lib/better_auth/context.rb +211 -0
- data/lib/better_auth/cookies.rb +278 -0
- data/lib/better_auth/core.rb +37 -1
- data/lib/better_auth/crypto/jwe.rb +76 -0
- data/lib/better_auth/crypto.rb +191 -0
- data/lib/better_auth/database_hooks.rb +114 -0
- data/lib/better_auth/endpoint.rb +326 -0
- data/lib/better_auth/error.rb +52 -0
- data/lib/better_auth/middleware/origin_check.rb +128 -0
- data/lib/better_auth/password.rb +120 -0
- data/lib/better_auth/plugin.rb +142 -0
- data/lib/better_auth/plugin_context.rb +16 -0
- data/lib/better_auth/plugin_registry.rb +67 -0
- data/lib/better_auth/plugins/access.rb +87 -0
- data/lib/better_auth/plugins/additional_fields.rb +29 -0
- data/lib/better_auth/plugins/admin/schema.rb +28 -0
- data/lib/better_auth/plugins/admin.rb +518 -0
- data/lib/better_auth/plugins/anonymous.rb +198 -0
- data/lib/better_auth/plugins/api_key.rb +16 -0
- data/lib/better_auth/plugins/bearer.rb +128 -0
- data/lib/better_auth/plugins/captcha.rb +159 -0
- data/lib/better_auth/plugins/custom_session.rb +84 -0
- data/lib/better_auth/plugins/device_authorization.rb +302 -0
- data/lib/better_auth/plugins/email_otp.rb +536 -0
- data/lib/better_auth/plugins/expo.rb +88 -0
- data/lib/better_auth/plugins/generic_oauth.rb +780 -0
- data/lib/better_auth/plugins/have_i_been_pwned.rb +94 -0
- data/lib/better_auth/plugins/jwt.rb +482 -0
- data/lib/better_auth/plugins/last_login_method.rb +92 -0
- data/lib/better_auth/plugins/magic_link.rb +181 -0
- data/lib/better_auth/plugins/mcp.rb +342 -0
- data/lib/better_auth/plugins/multi_session.rb +173 -0
- data/lib/better_auth/plugins/oauth_protocol.rb +694 -0
- data/lib/better_auth/plugins/oauth_provider.rb +16 -0
- data/lib/better_auth/plugins/oauth_proxy.rb +257 -0
- data/lib/better_auth/plugins/oidc_provider.rb +597 -0
- data/lib/better_auth/plugins/one_tap.rb +154 -0
- data/lib/better_auth/plugins/one_time_token.rb +106 -0
- data/lib/better_auth/plugins/open_api.rb +489 -0
- data/lib/better_auth/plugins/organization/schema.rb +106 -0
- data/lib/better_auth/plugins/organization.rb +995 -0
- data/lib/better_auth/plugins/passkey.rb +16 -0
- data/lib/better_auth/plugins/phone_number.rb +321 -0
- data/lib/better_auth/plugins/scim.rb +16 -0
- data/lib/better_auth/plugins/siwe.rb +242 -0
- data/lib/better_auth/plugins/sso.rb +16 -0
- data/lib/better_auth/plugins/stripe.rb +16 -0
- data/lib/better_auth/plugins/two_factor.rb +514 -0
- data/lib/better_auth/plugins/username.rb +278 -0
- data/lib/better_auth/plugins.rb +46 -0
- data/lib/better_auth/rate_limiter.rb +232 -0
- data/lib/better_auth/request_ip.rb +70 -0
- data/lib/better_auth/router.rb +378 -0
- data/lib/better_auth/routes/account.rb +211 -0
- data/lib/better_auth/routes/email_verification.rb +111 -0
- data/lib/better_auth/routes/error.rb +102 -0
- data/lib/better_auth/routes/ok.rb +15 -0
- data/lib/better_auth/routes/password.rb +183 -0
- data/lib/better_auth/routes/session.rb +160 -0
- data/lib/better_auth/routes/sign_in.rb +90 -0
- data/lib/better_auth/routes/sign_out.rb +15 -0
- data/lib/better_auth/routes/sign_up.rb +196 -0
- data/lib/better_auth/routes/social.rb +367 -0
- data/lib/better_auth/routes/user.rb +205 -0
- data/lib/better_auth/schema/sql.rb +202 -0
- data/lib/better_auth/schema.rb +291 -0
- data/lib/better_auth/session.rb +122 -0
- data/lib/better_auth/session_store.rb +91 -0
- data/lib/better_auth/social_providers/apple.rb +91 -0
- data/lib/better_auth/social_providers/atlassian.rb +32 -0
- data/lib/better_auth/social_providers/base.rb +325 -0
- data/lib/better_auth/social_providers/cognito.rb +32 -0
- data/lib/better_auth/social_providers/discord.rb +81 -0
- data/lib/better_auth/social_providers/dropbox.rb +33 -0
- data/lib/better_auth/social_providers/facebook.rb +35 -0
- data/lib/better_auth/social_providers/figma.rb +31 -0
- data/lib/better_auth/social_providers/github.rb +74 -0
- data/lib/better_auth/social_providers/gitlab.rb +67 -0
- data/lib/better_auth/social_providers/google.rb +90 -0
- data/lib/better_auth/social_providers/huggingface.rb +31 -0
- data/lib/better_auth/social_providers/kakao.rb +32 -0
- data/lib/better_auth/social_providers/kick.rb +32 -0
- data/lib/better_auth/social_providers/line.rb +33 -0
- data/lib/better_auth/social_providers/linear.rb +44 -0
- data/lib/better_auth/social_providers/linkedin.rb +30 -0
- data/lib/better_auth/social_providers/microsoft_entra_id.rb +137 -0
- data/lib/better_auth/social_providers/naver.rb +31 -0
- data/lib/better_auth/social_providers/notion.rb +33 -0
- data/lib/better_auth/social_providers/paybin.rb +31 -0
- data/lib/better_auth/social_providers/paypal.rb +36 -0
- data/lib/better_auth/social_providers/polar.rb +31 -0
- data/lib/better_auth/social_providers/railway.rb +49 -0
- data/lib/better_auth/social_providers/reddit.rb +32 -0
- data/lib/better_auth/social_providers/roblox.rb +31 -0
- data/lib/better_auth/social_providers/salesforce.rb +38 -0
- data/lib/better_auth/social_providers/slack.rb +30 -0
- data/lib/better_auth/social_providers/spotify.rb +31 -0
- data/lib/better_auth/social_providers/tiktok.rb +35 -0
- data/lib/better_auth/social_providers/twitch.rb +39 -0
- data/lib/better_auth/social_providers/twitter.rb +32 -0
- data/lib/better_auth/social_providers/vercel.rb +47 -0
- data/lib/better_auth/social_providers/vk.rb +34 -0
- data/lib/better_auth/social_providers/wechat.rb +104 -0
- data/lib/better_auth/social_providers/zoom.rb +31 -0
- data/lib/better_auth/social_providers.rb +38 -0
- data/lib/better_auth/version.rb +1 -1
- data/lib/better_auth.rb +86 -2
- metadata +233 -21
- data/.ruby-version +0 -1
- data/.standard.yml +0 -12
- data/.vscode/settings.json +0 -22
- data/AGENTS.md +0 -50
- data/CLAUDE.md +0 -1
- data/CODE_OF_CONDUCT.md +0 -173
- data/CONTRIBUTING.md +0 -187
- data/Gemfile +0 -12
- data/Makefile +0 -207
- data/Rakefile +0 -25
- data/SECURITY.md +0 -28
- data/docker-compose.yml +0 -63
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: df93cdae06059d52fa2c3d35c5b173aba9025d5ac46bda0b93a7a8abc5045f40
|
|
4
|
+
data.tar.gz: adec802dade2610da15329266c91dcd46aecb8642165c29e364ce7db2829d217
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
|
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 :
|
|
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
|
|
273
|
+
Release is triggered by package-prefixed tags so each gem can ship independently.
|
|
187
274
|
|
|
188
275
|
```bash
|
|
189
|
-
# STEP 1: Update
|
|
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:
|
|
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.
|
|
208
|
-
2.
|
|
209
|
-
3. The workflow
|
|
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
|
|
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@
|
|
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
|