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.
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - ruby-head
7
+ - ree
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Strategy for authenticating to Shopify API using OmniAuth.
4
4
 
5
+ [![Build Status](https://secure.travis-ci.org/yevgenko/omniauth-shopify.png)](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: 'example.myshopify.com',
31
+ uid: 'some-store',
30
32
  info: {
31
- name: 'example.myshopify.com',
33
+ name: 'some-store',
34
+ urls: { site: 'https://some-store.myshopify.com/admin' }
32
35
  },
33
- credentials: {
34
- token: 'thetoken' # can be used to auth to the API
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
@@ -4,3 +4,5 @@ require 'rake/testtask'
4
4
  Rake::TestTask.new do |t|
5
5
  t.test_files = FileList['spec/**/*_spec.rb']
6
6
  end
7
+
8
+ task :default => :test
@@ -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
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Shopify
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -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
- url = identifier
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{ request.params[options.identifier_param.to_s] }
64
- info{ {:name => request.params[options.identifier_param.to_s]} }
65
- credentials{ {:token => self.token} }
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 query_parameters['shop']
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 token' do
71
- last_request.env['omniauth.auth']['credentials']['token'].must_equal query_parameters['t']
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.2
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-02-13 00:00:00.000000000Z
12
+ date: 2012-03-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth
16
- requirement: &17205819720 !ruby/object:Gem::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: *17205819720
24
+ version_requirements: *16165760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack-test
27
- requirement: &17205819280 !ruby/object:Gem::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: *17205819280
35
+ version_requirements: *16165240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &17205818820 !ruby/object:Gem::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: *17205818820
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/sinatra.rb
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