foxlogin 0.3.1 → 0.4.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 +12 -0
- data/README.md +32 -0
- data/lib/foxlogin/client.rb +39 -2
- data/lib/foxlogin/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cca95c0263fc1309f2f8b223e3f7f333de89d014b4c23b4e3d458612ad75c243
|
|
4
|
+
data.tar.gz: 4103460997051d12aa0cdfcc092f0b58e1bf54f0b752c07e9a627f96d994f5cb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a8718ffe2838c959d523caaab642d6be427b4bffca427043ef0db28e701fe65b2b20c26d9383ff9589727fc0da273c486547857edd2a7bd0e3295c5e3f8e5626
|
|
7
|
+
data.tar.gz: eaf84f696f1971769c5795fdd14b300145064c6b3eaa14f2fd5e53e080b894fca9f5ec61dd6bcd9a2886c437a4cf2623da84bf90383f8cc4b4fef2af19b21fd5
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.0 — 2026-12-03
|
|
4
|
+
|
|
5
|
+
- Google sign-in: `google_sign_in_url(redirect_uri:, state:, country:)`,
|
|
6
|
+
`exchange_google_code(code:)` (the `fox_code` on the redirect URI; returns `signed_in` or
|
|
7
|
+
`mfa_required`) and `complete_google_sign_up(ticket:, country:)` for a new user whose country
|
|
8
|
+
is needed. Works the same with Fox Login's Google app and with an application's own Google app.
|
|
9
|
+
- `get_app_config` returns the application's sign-in methods, providers and user fields;
|
|
10
|
+
`sign_up` takes `profile:` with the values of those fields. The user hash's `"profile"` holds
|
|
11
|
+
them.
|
|
12
|
+
- New error codes `method_disabled`, `missing_field`, `invalid_field` and `field_taken` arrive
|
|
13
|
+
as `FoxLogin::Error`; `details["field"]` names the field.
|
|
14
|
+
|
|
3
15
|
## 0.3.1 — 2026-12-02
|
|
4
16
|
|
|
5
17
|
- `FoxLogin::Admin` accepts per-application secret keys (`sk_live_…`) as well as organization
|
data/README.md
CHANGED
|
@@ -57,6 +57,38 @@ object implementing `#get(key)`, `#set(key, value)` and `#remove(key)` to persis
|
|
|
57
57
|
single in-flight refresh (`Mutex` + `ConditionVariable`), since refresh tokens rotate and two
|
|
58
58
|
parallel refreshes would otherwise end the session.
|
|
59
59
|
|
|
60
|
+
### Sign in with Google
|
|
61
|
+
|
|
62
|
+
```ruby
|
|
63
|
+
# Sign-in page: redirect the browser (the redirect URI must be listed under Redirect URLs).
|
|
64
|
+
state = SecureRandom.hex(16) # keep it in the user's session
|
|
65
|
+
redirect_to fox.google_sign_in_url(redirect_uri: "https://your.app/auth/callback", state: state)
|
|
66
|
+
|
|
67
|
+
# https://your.app/auth/callback — compare params["state"] first, then:
|
|
68
|
+
if params["fox_code"]
|
|
69
|
+
result = fox.exchange_google_code(code: params["fox_code"]) # "signed_in" or "mfa_required"
|
|
70
|
+
elsif params["fox_status"] == "country_required"
|
|
71
|
+
result = fox.complete_google_sign_up(ticket: params["fox_ticket"], country: "TR") # ask the user
|
|
72
|
+
elsif params["fox_error"]
|
|
73
|
+
# e.g. "access_denied"
|
|
74
|
+
end
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Whether Google shows Fox Login's app or your own Google app is set in the dashboard; the code is
|
|
78
|
+
the same in both cases.
|
|
79
|
+
|
|
80
|
+
### Sign-up fields
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
app = fox.get_app_config # sign-in methods, providers and user fields of the application
|
|
84
|
+
# app["user_fields"]["fields"]["username"]["mode"] == "required" -> show a required username input
|
|
85
|
+
fox.sign_up(email: email, password: password, country: "TR", profile: { "username" => "ayse", "plan" => "pro" })
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
A missing or invalid field raises `FoxLogin::Error` with code `missing_field` / `invalid_field`
|
|
89
|
+
(400) or `field_taken` (409); `err.details["field"]` names the field. A sign-in method that is
|
|
90
|
+
off answers `method_disabled` (403).
|
|
91
|
+
|
|
60
92
|
## Server: check tokens and manage users
|
|
61
93
|
|
|
62
94
|
```ruby
|
data/lib/foxlogin/client.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
4
|
require "time"
|
|
5
|
+
require "uri"
|
|
5
6
|
|
|
6
7
|
module FoxLogin
|
|
7
8
|
# End-user client: sign-up, sign-in, sessions. One instance per
|
|
@@ -65,11 +66,21 @@ module FoxLogin
|
|
|
65
66
|
@mutex.synchronize { @listeners.delete(listener) }
|
|
66
67
|
end
|
|
67
68
|
|
|
69
|
+
# The application's public configuration (GET /v1/client/app): name,
|
|
70
|
+
# region, which sign-in methods are on ("sign_in"), the providers and
|
|
71
|
+
# the user fields the sign-up form should show ("user_fields", each
|
|
72
|
+
# with mode "off" / "optional" / "required"). Returns the parsed Hash.
|
|
73
|
+
def get_app_config
|
|
74
|
+
Http.request(@transport, "GET", "#{@base_url}/v1/client/app", headers: { "x-fox-publishable-key" => @key })
|
|
75
|
+
end
|
|
76
|
+
|
|
68
77
|
# Always resolves to {"status" => "verification_sent"}, even when the
|
|
69
|
-
# address already has an account.
|
|
70
|
-
|
|
78
|
+
# address already has an account. +profile+ holds the values of the
|
|
79
|
+
# application's user fields (see #get_app_config).
|
|
80
|
+
def sign_up(email:, password:, country:, name: nil, profile: nil)
|
|
71
81
|
body = { email: email, password: password, country: country }
|
|
72
82
|
body[:name] = name if name
|
|
83
|
+
body[:profile] = profile if profile
|
|
73
84
|
post("/v1/client/sign_up", body)
|
|
74
85
|
end
|
|
75
86
|
|
|
@@ -110,6 +121,32 @@ module FoxLogin
|
|
|
110
121
|
complete_sign_in("/v1/client/password_reset/confirm", { email: email, code: code, password: password })
|
|
111
122
|
end
|
|
112
123
|
|
|
124
|
+
# The URL that starts Google sign-in; redirect the browser to it.
|
|
125
|
+
# +redirect_uri+ must be one of the application's redirect URLs. Fox
|
|
126
|
+
# Login picks the Google app itself (its own, or the application's own
|
|
127
|
+
# when set up in the dashboard), so the URL is the same in both modes.
|
|
128
|
+
# Keep +state+ in the user's session and compare it on return.
|
|
129
|
+
def google_sign_in_url(redirect_uri:, state: nil, country: nil)
|
|
130
|
+
query = { "publishable_key" => @key, "redirect_uri" => redirect_uri }
|
|
131
|
+
query["state"] = state if state && !state.empty?
|
|
132
|
+
query["country"] = country if country && !country.empty?
|
|
133
|
+
"#{@base_url}/v1/oauth/google/start?#{URI.encode_www_form(query)}"
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# On the redirect URI: exchanges the +fox_code+ query parameter for a
|
|
137
|
+
# session; returns "signed_in" or "mfa_required" like #sign_in. When the
|
|
138
|
+
# return carries fox_status=country_required and +fox_ticket+ instead,
|
|
139
|
+
# ask the user's country and call #complete_google_sign_up; +fox_error+
|
|
140
|
+
# means the sign-in did not finish.
|
|
141
|
+
def exchange_google_code(code:)
|
|
142
|
+
complete_sign_in("/v1/client/oauth/token", { code: code })
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# New Google user: creates the account in the chosen country and signs in.
|
|
146
|
+
def complete_google_sign_up(ticket:, country:)
|
|
147
|
+
complete_sign_in("/v1/client/oauth/complete", { ticket: ticket, country: country })
|
|
148
|
+
end
|
|
149
|
+
|
|
113
150
|
# A valid access token, refreshed first when it expires within 60
|
|
114
151
|
# seconds; nil when signed out. Concurrent calls share one refresh
|
|
115
152
|
# (refresh tokens rotate, so two parallel refreshes would end the
|
data/lib/foxlogin/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: foxlogin
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- METANETSOFT
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-12-
|
|
11
|
+
date: 2026-12-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: jwt
|