omniauth-shopify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-shopify.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # OmniAuth Shopify Strategy
2
+
3
+ Strategy for authenticating to Shopify API using OmniAuth.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'omniauth-shopify'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ First, you will need to [register an application](http://www.shopify.com/partners/apps) with Shopify and obtain an API key. Once you do that, you can use it like so:
16
+
17
+ ```ruby
18
+ use OmniAuth::Builder do
19
+ provider :shopify, 'api_key', 'shared_secret'
20
+ end
21
+ ```
22
+
23
+ ## Auth Hash Schema
24
+
25
+ The following information is provided back to you for this provider:
26
+
27
+ ```ruby
28
+ {
29
+ uid: 'example.myshopify.com',
30
+ info: {
31
+ name: 'example.myshopify.com',
32
+ },
33
+ credentials: {
34
+ token: 'thetoken' # can be used to auth to the API
35
+ }
36
+ }
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ $:.push File.dirname(__FILE__) + '/../lib'
2
+
3
+ require 'sinatra'
4
+ require 'omniauth-shopify'
5
+
6
+ use Rack::Session::Cookie
7
+ use OmniAuth::Strategies::Shopify, ENV['SHOPIFY_KEY'], ENV['SHOPIFY_SECRET']
8
+
9
+ get '/' do
10
+ <<-HTML
11
+ <ul>
12
+ <li><a href='/auth/shopify'>Sign in with Shopify</a></li>
13
+ </ul>
14
+ HTML
15
+ end
16
+
17
+ get '/auth/shopify/callback' do
18
+ content_type 'text/plain'
19
+ request.env['omniauth.auth'].inspect
20
+ end
@@ -0,0 +1,68 @@
1
+ require 'omniauth'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Shopify
6
+ include OmniAuth::Strategy
7
+
8
+ args [:api_key, :secret]
9
+
10
+ option :api_key, nil
11
+ option :secret, nil
12
+ option :identifier, nil
13
+ option :identifier_param, 'shop'
14
+
15
+ attr_accessor :token
16
+
17
+ def identifier
18
+ i = options.identifier || request.params[options.identifier_param.to_s]
19
+ i = nil if i == ''
20
+ i
21
+ end
22
+
23
+ def get_identifier
24
+ f = OmniAuth::Form.new(:title => 'Shopify Authentication')
25
+ f.label_field('The URL of the Shop', options.identifier_param)
26
+ f.input_field('url', options.identifier_param)
27
+ f.to_response
28
+ end
29
+
30
+ 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]}"
36
+ end
37
+
38
+ def start
39
+ redirect create_permission_url
40
+ end
41
+
42
+ def validate_signature(params)
43
+ signature = params.delete('signature')
44
+ sorted_params = params.collect{|k,v|"#{k}=#{v}"}.sort.join
45
+ Digest::MD5.hexdigest(options.secret + sorted_params) == signature
46
+ end
47
+
48
+ ##
49
+ # Authentication Lifecycle
50
+ ##
51
+
52
+ def request_phase
53
+ identifier ? start : get_identifier
54
+ end
55
+
56
+ def callback_phase
57
+ params = request.params
58
+ return fail!(:invalid_response) unless validate_signature(params) && params['timestamp'].to_i > (Time.now - 24 * 3600).utc.to_i
59
+ self.token = params['t']
60
+ super
61
+ end
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} }
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Shopify
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-shopify/version"
2
+ require 'omniauth/strategies/shopify'
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-shopify/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-shopify"
7
+ s.version = Omniauth::Shopify::VERSION
8
+ s.authors = ["Yevgeniy A. Viktorov"]
9
+ s.email = ["craftsman@yevgenko.me"]
10
+ s.homepage = ""
11
+ s.summary = %q{Shopify strategy for OmniAuth}
12
+ s.description = %q{Strategy for authenticating to Shopify API with OmniAuth.}
13
+
14
+ s.rubyforge_project = "omniauth-shopify"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency 'omniauth', '~> 1.0'
22
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-shopify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yevgeniy A. Viktorov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: &17205853220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *17205853220
25
+ description: Strategy for authenticating to Shopify API with OmniAuth.
26
+ email:
27
+ - craftsman@yevgenko.me
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - examples/sinatra.rb
37
+ - lib/omniauth-shopify.rb
38
+ - lib/omniauth-shopify/version.rb
39
+ - lib/omniauth/strategies/shopify.rb
40
+ - omniauth-shopify.gemspec
41
+ homepage: ''
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project: omniauth-shopify
61
+ rubygems_version: 1.8.15
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Shopify strategy for OmniAuth
65
+ test_files: []