omniauth-printful 0.0.0 → 0.2.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 +41 -0
- data/LICENSE +21 -0
- data/README.md +121 -0
- data/lib/omniauth/printful/version.rb +7 -0
- data/lib/omniauth/strategies/printful.rb +65 -0
- data/lib/omniauth-printful.rb +1 -0
- metadata +21 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 58664dfbd8e5f6485d4e2f32f05aefbb90e724bd613ead985812d9f682db5817
|
|
4
|
+
data.tar.gz: fe0bf6739cd84d7de300ba3bc4dce86151600a5a07eecefb31a89259255b574a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 53693119000626bf058d789d8727d14743005739811cb1bd28e0f7ae514b56affde32ac8b581126750b560bd79f49f36217e69802e803c74a9687aa623995090
|
|
7
|
+
data.tar.gz: a4f1056f09514658feb81071967e69a39150f4b064b7f9d1159092dcd54ec542b1ef785c0cac180021978640134e74206e574b117a6ccaba017e147ee085a182
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.2.0] - 2026-07-10
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Token exchange now sends the client credentials in the request body
|
|
12
|
+
(`auth_scheme: :request_body`). oauth2 2.x defaults to HTTP Basic auth, which
|
|
13
|
+
Printful's token endpoint does not accept.
|
|
14
|
+
- Token exchange no longer sends a `redirect_uri`. Printful rejects it at
|
|
15
|
+
exchange time (the callback location is supplied as `redirect_url` during the
|
|
16
|
+
authorize step only).
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- A denied authorization (Printful returns `success=0` rather than the standard
|
|
20
|
+
`error` parameter) now fails cleanly as `:access_denied` instead of surfacing
|
|
21
|
+
as a misleading `:csrf_detected` or `:invalid_credentials` error.
|
|
22
|
+
|
|
23
|
+
### Notes
|
|
24
|
+
- State verification remains enabled by default. If Printful does not echo the
|
|
25
|
+
`state` parameter back on the callback, configure the provider with
|
|
26
|
+
`provider_ignores_state: true`. See the README.
|
|
27
|
+
|
|
28
|
+
## [0.1.0] - 2026-06-15
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
- The packaged gem now includes the strategy source files. Previously only
|
|
32
|
+
`lib/omniauth-printful.rb` was shipped, so the installed gem raised a
|
|
33
|
+
`LoadError`.
|
|
34
|
+
- `uid` is now the authenticated store's id instead of a random UUID, so host
|
|
35
|
+
applications can recognise returning users.
|
|
36
|
+
|
|
37
|
+
### Added
|
|
38
|
+
- `info` now exposes the store `name`, and `extra.raw_info` contains the full
|
|
39
|
+
`GET /stores` response.
|
|
40
|
+
- Gem metadata (homepage, source code, changelog, and bug tracker URIs).
|
|
41
|
+
- MIT `LICENSE` file.
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 David English
|
|
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,121 @@
|
|
|
1
|
+
# OmniAuth Printful
|
|
2
|
+
|
|
3
|
+
This gem contains the [Printful](https://www.printful.com) strategy for
|
|
4
|
+
[OmniAuth](https://github.com/omniauth/omniauth).
|
|
5
|
+
|
|
6
|
+
## Installing
|
|
7
|
+
|
|
8
|
+
Add to your `Gemfile`:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
gem 'omniauth-printful'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Then run `bundle install`.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Register an application in the [Printful Developer
|
|
19
|
+
Portal](https://developers.printful.com/) to obtain a client id and client
|
|
20
|
+
secret, and configure its redirect URL to point at your callback route (by
|
|
21
|
+
default `/auth/printful/callback`).
|
|
22
|
+
|
|
23
|
+
Add the strategy to your OmniAuth builder:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
use OmniAuth::Builder do
|
|
27
|
+
provider :printful, ENV['PRINTFUL_CLIENT_ID'], ENV['PRINTFUL_CLIENT_SECRET']
|
|
28
|
+
end
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
In Rails, this typically lives in `config/initializers/omniauth.rb`:
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
|
35
|
+
provider :printful, ENV['PRINTFUL_CLIENT_ID'], ENV['PRINTFUL_CLIENT_SECRET']
|
|
36
|
+
end
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Scopes
|
|
40
|
+
|
|
41
|
+
Printful uses scopes to limit what an access token may do (for example
|
|
42
|
+
`orders`, `stores_list`, `sync_products`, `file_library`, `webhooks`). The
|
|
43
|
+
scopes available to your token are configured for your app in the Developer
|
|
44
|
+
Portal. You can request a specific set at runtime with the `scope` option:
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
provider :printful, ENV['PRINTFUL_CLIENT_ID'], ENV['PRINTFUL_CLIENT_SECRET'],
|
|
48
|
+
scope: 'orders stores_list'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Printful-specific behaviour
|
|
52
|
+
|
|
53
|
+
Printful's OAuth 2.0 implementation departs from the specification in a few
|
|
54
|
+
ways. This strategy handles them for you, but they are worth knowing about:
|
|
55
|
+
|
|
56
|
+
- **Authorize request** uses a `redirect_url` parameter instead of the standard
|
|
57
|
+
`redirect_uri`.
|
|
58
|
+
- **Token exchange** sends the client credentials in the request body and does
|
|
59
|
+
**not** accept a `redirect_uri`. The strategy sets `auth_scheme: :request_body`
|
|
60
|
+
and omits the redirect parameter accordingly.
|
|
61
|
+
- **Denied authorization** comes back as `success=0` rather than a standard
|
|
62
|
+
`error` parameter. The strategy translates this into a clean OmniAuth
|
|
63
|
+
`:access_denied` failure.
|
|
64
|
+
|
|
65
|
+
#### CSRF / `state`
|
|
66
|
+
|
|
67
|
+
State verification is enabled by default. If you find authentications failing
|
|
68
|
+
with `:csrf_detected`, Printful is not echoing the `state` parameter back on the
|
|
69
|
+
callback; disable the check with:
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
provider :printful, ENV['PRINTFUL_CLIENT_ID'], ENV['PRINTFUL_CLIENT_SECRET'],
|
|
73
|
+
provider_ignores_state: true
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
In Rails, the request phase is still protected against CSRF by
|
|
77
|
+
[omniauth-rails_csrf_protection](https://github.com/cookpad/omniauth-rails_csrf_protection),
|
|
78
|
+
which requires the request phase to be initiated with a POST.
|
|
79
|
+
|
|
80
|
+
## Auth Hash
|
|
81
|
+
|
|
82
|
+
After a successful authentication, `request.env['omniauth.auth']` looks like
|
|
83
|
+
this (the `uid` is the authenticated Printful store's id):
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
{
|
|
87
|
+
"provider" => "printful",
|
|
88
|
+
"uid" => "10",
|
|
89
|
+
"info" => {
|
|
90
|
+
"name" => "My Store"
|
|
91
|
+
},
|
|
92
|
+
"credentials" => {
|
|
93
|
+
"token" => "...",
|
|
94
|
+
"refresh_token" => "...",
|
|
95
|
+
"expires_at" => 1718000000,
|
|
96
|
+
"expires" => true
|
|
97
|
+
},
|
|
98
|
+
"extra" => {
|
|
99
|
+
"raw_info" => {
|
|
100
|
+
"code" => 200,
|
|
101
|
+
"result" => [
|
|
102
|
+
{ "id" => 10, "name" => "My Store", "type" => "native" }
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Development
|
|
110
|
+
|
|
111
|
+
After checking out the repo, run `bundle install`, then run the tests and
|
|
112
|
+
linter:
|
|
113
|
+
|
|
114
|
+
```sh
|
|
115
|
+
bundle exec rspec
|
|
116
|
+
bundle exec rubocop
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
Released under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'omniauth/strategies/oauth2'
|
|
4
|
+
|
|
5
|
+
module OmniAuth
|
|
6
|
+
module Strategies
|
|
7
|
+
class Printful < OmniAuth::Strategies::OAuth2
|
|
8
|
+
API_SITE = 'https://api.printful.com'
|
|
9
|
+
|
|
10
|
+
option :name, 'printful'
|
|
11
|
+
|
|
12
|
+
option :client_options, {
|
|
13
|
+
site: 'https://www.printful.com',
|
|
14
|
+
authorize_url: 'https://www.printful.com/oauth/authorize',
|
|
15
|
+
token_url: 'https://www.printful.com/oauth/token',
|
|
16
|
+
auth_scheme: :request_body
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
uid { store['id']&.to_s }
|
|
20
|
+
|
|
21
|
+
info do
|
|
22
|
+
{
|
|
23
|
+
name: store['name']
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
extra do
|
|
28
|
+
{
|
|
29
|
+
'raw_info' => raw_info
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def raw_info
|
|
34
|
+
@raw_info ||= access_token.get("#{API_SITE}/stores").parsed || {}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def store
|
|
38
|
+
@store ||= Array(raw_info['result']).first || {}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def request_phase
|
|
42
|
+
redirect client.auth_code.authorize_url({ redirect_url: callback_url }.merge(authorize_params))
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def callback_phase
|
|
46
|
+
if request.params['error'].nil? && request.params['success'] == '0'
|
|
47
|
+
error = CallbackError.new('access_denied', 'The user denied the Printful authorization request')
|
|
48
|
+
return fail!(:access_denied, error)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
super
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
protected
|
|
55
|
+
|
|
56
|
+
def build_access_token
|
|
57
|
+
client.auth_code.get_token(
|
|
58
|
+
request.params['code'],
|
|
59
|
+
token_params.to_hash(symbolize_keys: true),
|
|
60
|
+
deep_symbolize(options.auth_token_params)
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
data/lib/omniauth-printful.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: omniauth-printful
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David English
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: omniauth-oauth2
|
|
@@ -17,6 +16,9 @@ dependencies:
|
|
|
17
16
|
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
18
|
version: 1.4.0
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '2.0'
|
|
20
22
|
type: :runtime
|
|
21
23
|
prerelease: false
|
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -24,19 +26,30 @@ dependencies:
|
|
|
24
26
|
- - ">="
|
|
25
27
|
- !ruby/object:Gem::Version
|
|
26
28
|
version: 1.4.0
|
|
27
|
-
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '2.0'
|
|
32
|
+
description: An OmniAuth OAuth2 strategy for authenticating with Printful.
|
|
28
33
|
email: davidenglishcodes@gmail.com
|
|
29
34
|
executables: []
|
|
30
35
|
extensions: []
|
|
31
36
|
extra_rdoc_files: []
|
|
32
37
|
files:
|
|
38
|
+
- CHANGELOG.md
|
|
39
|
+
- LICENSE
|
|
40
|
+
- README.md
|
|
33
41
|
- lib/omniauth-printful.rb
|
|
34
|
-
|
|
42
|
+
- lib/omniauth/printful/version.rb
|
|
43
|
+
- lib/omniauth/strategies/printful.rb
|
|
44
|
+
homepage: https://github.com/davidenglishmusic/omniauth-printful
|
|
35
45
|
licenses:
|
|
36
46
|
- MIT
|
|
37
47
|
metadata:
|
|
48
|
+
homepage_uri: https://github.com/davidenglishmusic/omniauth-printful
|
|
49
|
+
source_code_uri: https://github.com/davidenglishmusic/omniauth-printful
|
|
50
|
+
changelog_uri: https://github.com/davidenglishmusic/omniauth-printful/blob/main/CHANGELOG.md
|
|
51
|
+
bug_tracker_uri: https://github.com/davidenglishmusic/omniauth-printful/issues
|
|
38
52
|
rubygems_mfa_required: 'true'
|
|
39
|
-
post_install_message:
|
|
40
53
|
rdoc_options: []
|
|
41
54
|
require_paths:
|
|
42
55
|
- lib
|
|
@@ -44,15 +57,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
44
57
|
requirements:
|
|
45
58
|
- - ">="
|
|
46
59
|
- !ruby/object:Gem::Version
|
|
47
|
-
version:
|
|
60
|
+
version: '3.3'
|
|
48
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
62
|
requirements:
|
|
50
63
|
- - ">="
|
|
51
64
|
- !ruby/object:Gem::Version
|
|
52
65
|
version: '0'
|
|
53
66
|
requirements: []
|
|
54
|
-
rubygems_version:
|
|
55
|
-
signing_key:
|
|
67
|
+
rubygems_version: 4.0.6
|
|
56
68
|
specification_version: 4
|
|
57
69
|
summary: Printful strategy for OmniAuth
|
|
58
70
|
test_files: []
|