fulfil_api 0.8.0 → 0.8.1
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 +7 -0
- data/lib/fulfil_api/oauth/authorization.rb +12 -3
- data/lib/fulfil_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b1e3793aadb8a9615fdddb8970acbc23564eec7965e8655558cc9062bdb43c00
|
|
4
|
+
data.tar.gz: fbae55d2bec65240dbbb44370411b452bb2461a8021668f70be3af67ee1decfe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4cd81653bfe993a17a6552adfaceef0c0ea22f351ae900cc63dd436eb8461767c9d494d372cdc9458f44b5e5af0f6e4860aad49eabdca079ce5e59a32df15c53
|
|
7
|
+
data.tar.gz: cbf055f30acca04e2eeaf6aa510d90345ca603e50e016154626e363adca1e92f9a8f4e01f98bb238e32bb656a9d39b597071fb94f20d62cf1f98e09974e523ff
|
data/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
- Send the `grant_type` and `redirect_uri` in the form body when exchanging an authorization code, the way OAuth 2.0 defines the token request. The grant type used to travel in the query string and the redirect URI was left out, which Fulfil accepts today but isn't required to.
|
|
4
|
+
|
|
5
|
+
- Separate the requested OAuth scopes with spaces instead of commas. Fulfil didn't recognize the comma separated list, and a workspace granted every scope the approving user had rather than the ones that were asked for.
|
|
6
|
+
|
|
3
7
|
- Require Rails 8.0 and Ruby 3.2 or newer. Every application using the gem is on Rails 8 already, so carrying support for older versions bought nothing.
|
|
4
8
|
|
|
5
9
|
- Add support for Fulfil's OAuth 2.0 authorization flow, so applications no longer depend on personal access tokens now that Fulfil caps their lifetime. `FulfilApi::OAuth::Authorization` builds the consent screen URL and exchanges the authorization code for a token, and `config.oauth` holds the OAuth app's credentials.
|
|
10
|
+
|
|
6
11
|
- Ship the flow as a Rails engine that is only loaded inside a Rails application. `bin/rails generate fulfil_api:install` writes the initializer, adds the migration for `FulfilApi::Installation`, and mounts the engine. Installing changes nothing about how an application behaves until `config.oauth.parent_controller` names the controller the flow runs under, so an application still on personal access tokens can move to OAuth in its own time. There is no default: the engine's controllers inherit from it, and guessing wrong leaves an endpoint a stranger can use to record their own Fulfil workspace over the application's.
|
|
12
|
+
|
|
7
13
|
- Add the `FulfilApi::Authenticated` controller concern, which runs every action with a client authenticated as the current installation and sends a user without a usable token through the OAuth flow.
|
|
14
|
+
|
|
8
15
|
- Add the `FulfilApi::Installable` model concern, so an application serving many merchants can keep one installation per record instead of one for the whole application. A record is connected to a single Fulfil workspace.
|
|
9
16
|
|
|
10
17
|
- Add an optional circuit breaker, backed by [Faulty](https://github.com/ParentSquare/faulty), that stops sending requests to a Fulfil instance that keeps failing, so a struggling instance can't tie up every thread of an application that talks to several of them. Pass a `Faulty` instance as `circuit_breaker`; each Fulfil instance gets its own circuit, and while it's open requests raise a `FulfilApi::CircuitOpen` without touching the network.
|
|
@@ -96,8 +96,7 @@ module FulfilApi
|
|
|
96
96
|
def exchange(code)
|
|
97
97
|
raise TokenExchangeFailed, "No authorization code was provided" if code.blank?
|
|
98
98
|
|
|
99
|
-
response = connection.post(TOKEN_PATH,
|
|
100
|
-
request.params["grant_type"] = "authorization_code"
|
|
99
|
+
response = connection.post(TOKEN_PATH, token_parameters(code)) do |request|
|
|
101
100
|
request.headers["Authorization"] = "Basic #{basic_credentials}"
|
|
102
101
|
end
|
|
103
102
|
|
|
@@ -154,6 +153,16 @@ module FulfilApi
|
|
|
154
153
|
}
|
|
155
154
|
end
|
|
156
155
|
|
|
156
|
+
# @param code [String] The authorization code Fulfil sent to the callback.
|
|
157
|
+
# @return [Hash]
|
|
158
|
+
def token_parameters(code)
|
|
159
|
+
{
|
|
160
|
+
code: code,
|
|
161
|
+
grant_type: "authorization_code",
|
|
162
|
+
redirect_uri: redirect_uri
|
|
163
|
+
}.compact
|
|
164
|
+
end
|
|
165
|
+
|
|
157
166
|
# @param state [String] The nonce to verify the callback with.
|
|
158
167
|
# @return [Hash]
|
|
159
168
|
def url_parameters(state)
|
|
@@ -164,7 +173,7 @@ module FulfilApi
|
|
|
164
173
|
response_type: "code",
|
|
165
174
|
state: state
|
|
166
175
|
}.tap do |parameters|
|
|
167
|
-
parameters[:scope] = scopes.join("
|
|
176
|
+
parameters[:scope] = scopes.join(" ") if scopes.any?
|
|
168
177
|
end.compact
|
|
169
178
|
end
|
|
170
179
|
end
|
data/lib/fulfil_api/version.rb
CHANGED