omniauth-shopify 0.0.2 → 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.
- data/.travis.yml +7 -0
- data/README.md +24 -4
- data/Rakefile +2 -0
- data/examples/api_consumer.rb +23 -0
- data/examples/{sinatra.rb → auth_hash.rb} +0 -0
- data/lib/omniauth-shopify/version.rb +1 -1
- data/lib/omniauth/strategies/shopify.rb +14 -8
- data/spec/omniauth/strategies/shopify_spec.rb +15 -3
- metadata +11 -9
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
Strategy for authenticating to Shopify API using OmniAuth.
|
4
4
|
|
5
|
+
[](http://travis-ci.org/yevgenko/omniauth-shopify)
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
@@ -26,16 +28,29 @@ The following information is provided back to you for this provider:
|
|
26
28
|
|
27
29
|
```ruby
|
28
30
|
{
|
29
|
-
uid: '
|
31
|
+
uid: 'some-store',
|
30
32
|
info: {
|
31
|
-
name: '
|
33
|
+
name: 'some-store',
|
34
|
+
urls: { site: 'https://some-store.myshopify.com/admin' }
|
32
35
|
},
|
33
|
-
credentials: {
|
34
|
-
|
36
|
+
credentials: { # basic auth
|
37
|
+
username: 'api_key',
|
38
|
+
password: 'password'
|
35
39
|
}
|
36
40
|
}
|
37
41
|
```
|
38
42
|
|
43
|
+
## Examples
|
44
|
+
|
45
|
+
[examples/][] directory contains few simple [sinatra][] apps:
|
46
|
+
|
47
|
+
* auth_hash.rb - displays auth hash schema
|
48
|
+
* api_consumer.rb - consuming api with [httparty][]
|
49
|
+
|
50
|
+
So, make sure you have [sinatra][] and [httparty][] gems and run it as follow:
|
51
|
+
|
52
|
+
SHOPIFY_KEY="apikey" SHOPIFY_SECRET="secret" ruby auth_hash.rb
|
53
|
+
|
39
54
|
## Contributing
|
40
55
|
|
41
56
|
1. Fork it
|
@@ -43,3 +58,8 @@ The following information is provided back to you for this provider:
|
|
43
58
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
44
59
|
4. Push to the branch (`git push origin my-new-feature`)
|
45
60
|
5. Create new Pull Request
|
61
|
+
|
62
|
+
|
63
|
+
[examples/]:https://github.com/yevgenko/omniauth-shopify/tree/master/examples
|
64
|
+
[sinatra]:http://www.sinatrarb.com/
|
65
|
+
[httparty]:https://github.com/jnunemaker/httparty
|
data/Rakefile
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.push File.dirname(__FILE__) + '/../lib'
|
2
|
+
|
3
|
+
require 'sinatra'
|
4
|
+
require 'omniauth-shopify'
|
5
|
+
require 'httparty'
|
6
|
+
|
7
|
+
use Rack::Session::Cookie
|
8
|
+
use OmniAuth::Strategies::Shopify, ENV['SHOPIFY_KEY'], ENV['SHOPIFY_SECRET']
|
9
|
+
|
10
|
+
get '/' do
|
11
|
+
<<-HTML
|
12
|
+
<ul>
|
13
|
+
<li><a href='/auth/shopify'>Sign in with Shopify</a></li>
|
14
|
+
</ul>
|
15
|
+
HTML
|
16
|
+
end
|
17
|
+
|
18
|
+
get '/auth/shopify/callback' do
|
19
|
+
content_type 'text/plain'
|
20
|
+
url = request.env['omniauth.auth']['info']['urls']['site']
|
21
|
+
credentials = request.env['omniauth.auth']['credentials']
|
22
|
+
HTTParty.get("#{url}/orders.json?limit=5", :basic_auth => credentials, :headers => { 'ContentType' => 'application/json' }).inspect
|
23
|
+
end
|
File without changes
|
@@ -17,6 +17,10 @@ module OmniAuth
|
|
17
17
|
def identifier
|
18
18
|
i = options.identifier || request.params[options.identifier_param.to_s]
|
19
19
|
i = nil if i == ''
|
20
|
+
if i
|
21
|
+
i.gsub!(/https?:\/\//, '') # remove http:// or https://
|
22
|
+
i.gsub!(/\..*/, '') # remove .myshopify.com
|
23
|
+
end
|
20
24
|
i
|
21
25
|
end
|
22
26
|
|
@@ -28,11 +32,7 @@ module OmniAuth
|
|
28
32
|
end
|
29
33
|
|
30
34
|
def create_permission_url
|
31
|
-
|
32
|
-
url.gsub!(/https?:\/\//, '') # remove http:// or https://
|
33
|
-
url.concat(".myshopify.com") unless url.include?('.') # extend url to myshopify.com if no host is given
|
34
|
-
|
35
|
-
"http://#{url}/admin/api/auth?api_key=#{options[:api_key]}"
|
35
|
+
"http://#{identifier}.myshopify.com/admin/api/auth?api_key=#{options[:api_key]}"
|
36
36
|
end
|
37
37
|
|
38
38
|
def start
|
@@ -60,9 +60,15 @@ module OmniAuth
|
|
60
60
|
super
|
61
61
|
end
|
62
62
|
|
63
|
-
uid{
|
64
|
-
info{ {
|
65
|
-
|
63
|
+
uid{ identifier }
|
64
|
+
info{ {
|
65
|
+
:name => identifier,
|
66
|
+
:urls => {:site => "https://#{identifier}.myshopify.com/admin"}
|
67
|
+
} }
|
68
|
+
credentials{ { # basic auth
|
69
|
+
:username => options.api_key,
|
70
|
+
:password => Digest::MD5.hexdigest(options.secret + self.token)
|
71
|
+
} }
|
66
72
|
end
|
67
73
|
end
|
68
74
|
end
|
@@ -41,6 +41,10 @@ describe OmniAuth::Strategies::Shopify do
|
|
41
41
|
Digest::MD5.hexdigest('hush' + calculated_signature.sort.join)
|
42
42
|
end
|
43
43
|
|
44
|
+
def password
|
45
|
+
Digest::MD5.hexdigest('hush' + query_parameters['t'])
|
46
|
+
end
|
47
|
+
|
44
48
|
describe '#request_phase' do
|
45
49
|
it 'must prompt for a shop url' do
|
46
50
|
get '/auth/shopify'
|
@@ -64,11 +68,19 @@ describe OmniAuth::Strategies::Shopify do
|
|
64
68
|
end
|
65
69
|
|
66
70
|
it 'must have proper uid' do
|
67
|
-
last_request.env['omniauth.auth']['uid'].must_equal
|
71
|
+
last_request.env['omniauth.auth']['uid'].must_equal 'some-shop'
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'must have site URL' do
|
75
|
+
last_request.env['omniauth.auth']['info']['urls']['site'].must_equal "https://some-shop.myshopify.com/admin"
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'must have username' do
|
79
|
+
last_request.env['omniauth.auth']['credentials']['username'].must_equal 'apikey'
|
68
80
|
end
|
69
81
|
|
70
|
-
it 'must have
|
71
|
-
last_request.env['omniauth.auth']['credentials']['
|
82
|
+
it 'must have password' do
|
83
|
+
last_request.env['omniauth.auth']['credentials']['password'].must_equal password
|
72
84
|
end
|
73
85
|
end
|
74
86
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-shopify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-23 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: omniauth
|
16
|
-
requirement: &
|
16
|
+
requirement: &16165760 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *16165760
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rack-test
|
27
|
-
requirement: &
|
27
|
+
requirement: &16165240 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *16165240
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &16164740 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *16164740
|
47
47
|
description: Strategy for authenticating to Shopify API with OmniAuth.
|
48
48
|
email:
|
49
49
|
- craftsman@yevgenko.me
|
@@ -52,10 +52,12 @@ extensions: []
|
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
54
|
- .gitignore
|
55
|
+
- .travis.yml
|
55
56
|
- Gemfile
|
56
57
|
- README.md
|
57
58
|
- Rakefile
|
58
|
-
- examples/
|
59
|
+
- examples/api_consumer.rb
|
60
|
+
- examples/auth_hash.rb
|
59
61
|
- lib/omniauth-shopify.rb
|
60
62
|
- lib/omniauth-shopify/version.rb
|
61
63
|
- lib/omniauth/strategies/shopify.rb
|