omniauth-whop 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f40b76c685c120d98586cb32a4670b466134edbda04ee483b3a0de3b76cf59fc
4
+ data.tar.gz: 15ef0db76b1671082773a4da4f829770d77875a8d2478bc03ac85cdf86816d4e
5
+ SHA512:
6
+ metadata.gz: 4e7e8e928104b20a7e20e1cdef47316a5c321cb747df23d2fabb90fb14bdf63539aae8cc0ae14b96b7e388dda0217b7f9d4e6e65b025119b45022d7431b54cdf
7
+ data.tar.gz: be2e6da775f51fb68f3612918ba9460d7cc0a8dfb98a545beac4bbfd5e008d035da3dd8beb3d2dffe0903a5bbb58c56450ca4a6b91c27ad678916b0ef720a1fc
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Initial Whop OmniAuth strategy with PKCE, state and nonce validation.
6
+ - Verified ES256 ID tokens and matching UserInfo subjects.
7
+ - Standard OmniAuth user profile and token mapping.
8
+ - Sandbox support, Rails/Devise instructions, and a runnable Rack demo.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yaroslav Shmarov
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,153 @@
1
+ # OmniAuth Whop
2
+
3
+ [![CI](https://github.com/yshmarov/omniauth-whop/actions/workflows/ci.yml/badge.svg)](https://github.com/yshmarov/omniauth-whop/actions/workflows/ci.yml)
4
+
5
+ Add **Sign in with Whop** to a Ruby or Rails app.
6
+
7
+ A community-maintained [OmniAuth](https://github.com/omniauth/omniauth) strategy by [Yaroslav Shmarov](https://github.com/yshmarov). Not affiliated with or endorsed by Whop. For payments, see [pay-whop](https://github.com/yshmarov/pay-whop).
8
+
9
+ - Authorization code flow with S256 PKCE and state validation.
10
+ - Fresh nonce for each login; concurrent sign-ins supported.
11
+ - ES256 ID token signature, issuer, audience, expiry, issued-at, nonce, and authorized-party validation.
12
+ - UserInfo subject checked against the verified ID token.
13
+ - Sandbox support. No Rails or Whop SDK dependency.
14
+
15
+ Requires Ruby 3.2+ and OmniAuth 2 (via `omniauth-oauth2`).
16
+
17
+ Verified with a real Whop sandbox login on November 15, 2026: authorization, code exchange, signature/claim validation, and UserInfo profile mapping. Production credentials have not been exercised.
18
+
19
+ ## Installation
20
+
21
+ ```ruby
22
+ # Gemfile
23
+ gem "omniauth-whop"
24
+
25
+ # Rails applications also need request-phase CSRF protection:
26
+ gem "omniauth-rails_csrf_protection"
27
+ ```
28
+
29
+ Then run `bundle install`.
30
+
31
+ ## Configure your Whop app
32
+
33
+ 1. Open your business's **Developer → Apps** page in [Whop sandbox](https://sandbox.whop.com/).
34
+ 2. Create an app and open its OAuth settings. Use a name such as `OmniAuth Ruby Sandbox`; Whop rejects app names containing `whop`.
35
+ 3. Register your exact callback URL, including protocol and path:
36
+ - Rails: `http://localhost:3000/auth/whop/callback`
37
+ - Devise: `http://localhost:3000/users/auth/whop/callback`
38
+ - Included Rack demo: `http://localhost:9292/auth/whop/callback`
39
+ 4. Save the app's client ID and client secret as `WHOP_CLIENT_ID` and `WHOP_CLIENT_SECRET`.
40
+ 5. Under **Permissions**, add `oauth:token_exchange`, enter a short explanation, and save. This app API key permission enables the client secret to exchange authorization codes. It is separate from the user-facing `openid profile email` OAuth scopes. See [Whop's authentication guide](https://whop.com/blog/add-user-authentication/).
41
+
42
+ Use credentials from the same environment as the strategy. Register an HTTPS callback for production and omit `sandbox: true`.
43
+
44
+ ## Rails
45
+
46
+ ```ruby
47
+ # config/initializers/omniauth.rb
48
+ Rails.application.config.middleware.use OmniAuth::Builder do
49
+ provider :whop,
50
+ ENV.fetch("WHOP_CLIENT_ID"),
51
+ ENV.fetch("WHOP_CLIENT_SECRET"),
52
+ sandbox: ENV["WHOP_SANDBOX"] == "true"
53
+ end
54
+ ```
55
+
56
+ Initiate sign-in with a POST form:
57
+
58
+ ```erb
59
+ <%= button_to "Sign in with Whop", "/auth/whop", data: { turbo: false } %>
60
+ ```
61
+
62
+ Route `GET /auth/whop/callback` to your sessions controller and read `request.env["omniauth.auth"]`. Route `GET /auth/failure` to your failure handler. Your application owns account creation, account linking, and its login session.
63
+
64
+ Use `(provider, uid)` as the external identity. Do not automatically link existing accounts using an unverified email address. Email, name, nickname, and image may be absent.
65
+
66
+ ## Devise
67
+
68
+ Use Devise's configuration instead of installing the middleware a second time:
69
+
70
+ ```ruby
71
+ # config/initializers/devise.rb
72
+ config.omniauth :whop,
73
+ ENV.fetch("WHOP_CLIENT_ID"),
74
+ ENV.fetch("WHOP_CLIENT_SECRET"),
75
+ sandbox: ENV["WHOP_SANDBOX"] == "true"
76
+ ```
77
+
78
+ Add `:omniauthable, omniauth_providers: [:whop]` to your existing `devise` declaration, register an OmniAuth callbacks controller in your Devise routes, and implement its `whop` action using `request.env["omniauth.auth"]`.
79
+
80
+ ```erb
81
+ <%= button_to "Sign in with Whop", user_whop_omniauth_authorize_path,
82
+ data: { turbo: false } %>
83
+ ```
84
+
85
+ Keep `omniauth-rails_csrf_protection` installed for Devise too.
86
+
87
+ ## Auth hash
88
+
89
+ ```ruby
90
+ {
91
+ provider: "whop",
92
+ uid: "user_example",
93
+ info: {
94
+ name: "Example User",
95
+ nickname: "example",
96
+ email: "example@example.com",
97
+ email_verified: true,
98
+ image: "https://example.com/avatar.png"
99
+ },
100
+ credentials: {
101
+ token: "ACCESS_TOKEN",
102
+ refresh_token: "REFRESH_TOKEN", # when provided
103
+ expires_at: 1_800_000_000, # when provided
104
+ expires: true
105
+ },
106
+ extra: {
107
+ raw_info: { "sub" => "user_example", "..." => "..." }
108
+ }
109
+ }
110
+ ```
111
+
112
+ Tokens are credentials. Keep them out of logs and browser responses; encrypt them at rest if your application needs to retain them. This strategy authenticates users; checking purchases or membership access is a separate application concern.
113
+
114
+ ## Options
115
+
116
+ | Option | Default | Purpose |
117
+ | --- | --- | --- |
118
+ | `sandbox` | `false` | Use `https://sandbox-api.whop.com` for OAuth, UserInfo, and signing keys. Pass a Ruby boolean. |
119
+ | `scope` | `"openid profile email"` | Space-separated scopes. `openid` is always included because identity tokens are validated. |
120
+ | `issuer` | `"https://api.whop.com"` | Expected signed ID token issuer. Whop's sandbox discovery document advertises the same issuer. |
121
+ | `client_options` | Whop endpoints | Standard `omniauth-oauth2` client options. Requests default to 5-second connect and 15-second request timeouts. |
122
+
123
+ Leave PKCE and state validation enabled. The strategy fetches signing keys from the configured environment for each login, avoiding stale-key failures after rotation. Identity comes from a verified ID token plus the authenticated UserInfo endpoint; it never trusts a decoded, unverified JWT.
124
+
125
+ ## Run the sandbox demo
126
+
127
+ ```sh
128
+ git clone https://github.com/yshmarov/omniauth-whop.git
129
+ cd omniauth-whop
130
+ bundle install
131
+ cp .env.example .env
132
+ # Set the sandbox client ID and secret in .env.
133
+ bundle exec rackup examples/config.ru --host localhost --port 9292
134
+ ```
135
+
136
+ Open `http://localhost:9292` and click **Sign in with Whop**. The demo displays the provider, user ID, and profile after a successful callback. It does not display or save access/refresh tokens. Its generated session secret changes on restart; set `SESSION_SECRET` to a random value of at least 64 bytes for a stable local session.
137
+
138
+ ## Development
139
+
140
+ ```sh
141
+ bundle install
142
+ bundle exec rake
143
+ bundle exec rubocop
144
+ gem build omniauth-whop.gemspec
145
+ ```
146
+
147
+ Tests exercise the real OmniAuth middleware and HTTP boundary with generated signing keys and stubbed Whop responses. External HTTP is disabled in the test suite. CI runs Ruby 3.2, 3.3, 3.4, and 4.0.
148
+
149
+ Report bugs with a minimal reproduction, Ruby/gem versions, and the failure type. Do not include credentials, authorization codes, or customer data. To report a security issue privately, use [GitHub's security advisory form](https://github.com/yshmarov/omniauth-whop/security/advisories/new).
150
+
151
+ ## License
152
+
153
+ [MIT](LICENSE)
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth-oauth2"
4
+ require "jwt"
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ # Whop OAuth authorization-code flow with PKCE and verified OIDC identity.
9
+ class Whop < OAuth2
10
+ option :name, "whop"
11
+ option :scope, "openid profile email"
12
+ option :pkce, true
13
+ option :sandbox, false
14
+ # Whop's sandbox discovery document also advertises this issuer.
15
+ option :issuer, "https://api.whop.com"
16
+ option :client_options, {
17
+ site: "https://api.whop.com",
18
+ authorize_url: "/oauth/authorize",
19
+ token_url: "/oauth/token",
20
+ auth_scheme: :request_body,
21
+ connection_opts: { request: { timeout: 15, open_timeout: 5 } }
22
+ }
23
+
24
+ uid { raw_info.fetch("sub") }
25
+
26
+ info do
27
+ {
28
+ name: raw_info["name"],
29
+ nickname: raw_info["preferred_username"],
30
+ email: raw_info["email"],
31
+ image: raw_info["picture"],
32
+ email_verified: raw_info["email_verified"]
33
+ }.compact
34
+ end
35
+
36
+ extra { { raw_info: raw_info } }
37
+
38
+ def client
39
+ oauth_client = super
40
+ oauth_client.site = "https://sandbox-api.whop.com" if options.sandbox
41
+ oauth_client
42
+ end
43
+
44
+ def authorize_params
45
+ params = super
46
+ params[:scope] = (["openid"] + params[:scope].to_s.split).uniq.join(" ")
47
+ params[:nonce] = SecureRandom.urlsafe_base64(32)
48
+ nonces = session.fetch("omniauth.whop.nonces", {}).dup
49
+ nonces[params.fetch(:state)] = params[:nonce]
50
+ session["omniauth.whop.nonces"] = nonces.to_a.last(3).to_h
51
+ params
52
+ end
53
+
54
+ def callback_phase
55
+ nonces = session.fetch("omniauth.whop.nonces", {}).dup
56
+ @expected_nonce = nonces.delete(request.params["state"])
57
+ session["omniauth.whop.nonces"] = nonces
58
+ super
59
+ rescue JWT::DecodeError, JSON::ParserError, KeyError => e
60
+ fail!(:invalid_credentials, CallbackError.new(:invalid_identity, e.class.name))
61
+ end
62
+
63
+ def raw_info
64
+ @raw_info ||= begin
65
+ profile = access_token.get("/oauth/userinfo").parsed
66
+ unless profile.is_a?(Hash) && profile["sub"] == @id_token_claims.fetch("sub")
67
+ raise CallbackError.new(:invalid_identity, "UserInfo subject does not match ID token")
68
+ end
69
+
70
+ profile
71
+ end
72
+ end
73
+
74
+ def callback_url
75
+ full_host + callback_path
76
+ end
77
+
78
+ protected
79
+
80
+ def build_access_token
81
+ token = super
82
+ validate_id_token!(token.params["id_token"])
83
+ token
84
+ end
85
+
86
+ def validate_id_token!(id_token)
87
+ if id_token.to_s.empty? || @expected_nonce.to_s.empty?
88
+ raise CallbackError.new(:invalid_identity,
89
+ "Missing ID token or nonce")
90
+ end
91
+
92
+ jwks = client.request(:get, "/.well-known/jwks.json", parse: :json, snaky: false).parsed
93
+ @id_token_claims = JWT.decode(
94
+ id_token, nil, true,
95
+ algorithms: ["ES256"], jwks: jwks,
96
+ iss: options.issuer, verify_iss: true,
97
+ aud: options.client_id, verify_aud: true,
98
+ verify_iat: true, required_claims: %w[iss sub aud exp iat nonce]
99
+ ).first
100
+ unless secure_compare(@id_token_claims["nonce"].to_s, @expected_nonce)
101
+ raise CallbackError.new(:invalid_identity, "ID token nonce mismatch")
102
+ end
103
+ raise CallbackError.new(:invalid_identity, "Missing ID token subject") if @id_token_claims["sub"].to_s.empty?
104
+
105
+ audiences = Array(@id_token_claims["aud"])
106
+ authorized_party = @id_token_claims["azp"]
107
+ return unless (audiences.size > 1 || authorized_party) && authorized_party != options.client_id
108
+
109
+ raise CallbackError.new(:invalid_identity, "ID token authorized party mismatch")
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Whop
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth/whop/version"
4
+ require "omniauth/strategies/whop"
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-whop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yaroslav Shmarov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.9'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '2.9'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4'
33
+ - !ruby/object:Gem::Dependency
34
+ name: omniauth-oauth2
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.10'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.10.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.10'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.10.1
53
+ description: A community OmniAuth strategy for Whop with PKCE, verified OpenID Connect
54
+ ID tokens, and sandbox support.
55
+ email:
56
+ - yshmarov@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - CHANGELOG.md
62
+ - LICENSE
63
+ - README.md
64
+ - lib/omniauth-whop.rb
65
+ - lib/omniauth/strategies/whop.rb
66
+ - lib/omniauth/whop/version.rb
67
+ homepage: https://github.com/yshmarov/omniauth-whop
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ source_code_uri: https://github.com/yshmarov/omniauth-whop
72
+ changelog_uri: https://github.com/yshmarov/omniauth-whop/blob/main/CHANGELOG.md
73
+ rubygems_mfa_required: 'true'
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.5.22
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Sign in with Whop for OmniAuth
93
+ test_files: []