omniauth-ebay 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ OmniAuth eBay
2
+ ====================================
3
+
4
+ In this gem you will find an OmniAuth eBay strategy that is compliant with the Open eBay Apps API.
5
+ You can read all about it here: [Open eBay Apps Developers Zone](http://developer.ebay.com/DevZone/open-ebay-apps/Concepts/OpeneBayUGDev.html)
6
+
7
+ Usage
8
+ ------------------------------------------
9
+
10
+ Note: The examples are for a Rails app.
11
+
12
+ * Add our gem to your `Gemfile`
13
+ `gem 'omniauth-ebay'`
14
+
15
+ * Add to your omniauth initializer (`config/initializers/omniauth.rb`) the ebay strategy like so:
16
+
17
+ `Rails.application.config.middleware.use OmniAuth::Builder do
18
+
19
+ provider :ebay, "runame", "devid", "appid", "certid", "siteid", "apiurl"
20
+
21
+ end`
22
+
23
+ Insert your app credentials in the given order. You can find out these details by going into your developer's account at [eBay DevZone](https://developer.ebay.com/DevZone/account/)
24
+
25
+ * To use the strategy, you will need to access it's omniauth provider path: `/auth/ebay`. The callback phase path is the default one: `/auth/ebay/callback`.
26
+ You will need to define the callback path in your relevant app RUname, so don't forget to set the accept/reject paths in the devzone to the callback path.
27
+
28
+ * Set a route to the callback path of your sessions controller, and handle the session creation there. You will be able to access
29
+ the omniauth session data by accessing `request.env['omniauth.auth']`
30
+
31
+ How it Works
32
+ ====================================
33
+
34
+ Request Phase
35
+ --------------------
36
+
37
+ * API call to eBay, requesting a session id.
38
+ * Redirecting to eBay login with the session id.
39
+
40
+ Callback Phase
41
+ -----------------------------------------
42
+
43
+ * API call to eBay, requesting an ebay auth token, with the secret id and username retrieved from the request.
44
+ * API call to eBay, requesting the user's info by using the ebay auth token from the last call.
45
+ * The strategy's UID is the eBay EIAS Token. Also these fields will also be exposed by accessing `request.env['omniauth.auth'].info`:
46
+
47
+ `ebay_id` - The user's eBay username.
48
+
49
+ `ebay_token` - The current session's auth token, to be used for API calls.
50
+
51
+ `email` - The user's email address.
52
+ * Extra data - We're also passing an optional parameter, `return_to`, which allows you to specify a URL you want the redirect the user to when the authentication process is completed.
53
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/ebay_api.rb ADDED
@@ -0,0 +1,72 @@
1
+ module EbayAPI
2
+
3
+ EBAY_LOGIN_URL = "https://signin.ebay.com/ws/eBayISAPI.dll"
4
+ X_EBAY_API_REQUEST_CONTENT_TYPE = 'text/xml'
5
+ X_EBAY_API_COMPATIBILITY_LEVEL = '675'
6
+ X_EBAY_API_GETSESSIONID_CALL_NAME = 'GetSessionID'
7
+ X_EBAY_API_FETCHAUTHTOKEN_CALL_NAME = 'FetchToken'
8
+ X_EBAY_API_GETUSER_CALL_NAME = 'GetUser'
9
+
10
+ def generate_session_id
11
+ request = <<-END
12
+ <?xml version="1.0" encoding="utf-8"?>
13
+ <GetSessionIDRequest xmlns="urn:ebay:apis:eBLBaseComponents">
14
+ <RuName>#{options.runame}</RuName>
15
+ </GetSessionIDRequest>
16
+ END
17
+
18
+ response = api(X_EBAY_API_GETSESSIONID_CALL_NAME, request)
19
+ MultiXml.parse(response.content)["GetSessionIDResponse"]["SessionID"]
20
+ end
21
+
22
+ def get_auth_token(username, secret_id)
23
+ request = <<-END
24
+ <?xml version="1.0" encoding="utf-8"?>
25
+ <FetchTokenRequest xmlns="urn:ebay:apis:eBLBaseComponents">
26
+ <RequesterCredentials>
27
+ <Username>#{username}</Username>
28
+ </RequesterCredentials>
29
+ <SecretID>#{secret_id.gsub(' ', '+')}</SecretID>
30
+ </FetchTokenRequest>
31
+ END
32
+
33
+ response = api(X_EBAY_API_FETCHAUTHTOKEN_CALL_NAME, request)
34
+ MultiXml.parse(response.content)["FetchTokenResponse"]["eBayAuthToken"]
35
+ end
36
+
37
+ def get_user_info(auth_token)
38
+ request = <<-END
39
+ <?xml version="1.0" encoding="utf-8"?>
40
+ <GetUserRequest xmlns="urn:ebay:apis:eBLBaseComponents">
41
+ <RequesterCredentials>
42
+ <eBayAuthToken>#{auth_token}</eBayAuthToken>
43
+ </RequesterCredentials>
44
+ </GetUserRequest>
45
+ END
46
+
47
+ response = api(X_EBAY_API_GETUSER_CALL_NAME, request)
48
+ MultiXml.parse(response.content)["GetUserResponse"]['User']
49
+ end
50
+
51
+ protected
52
+
53
+ def api(call_name, request)
54
+ headers = ebay_request_headers(call_name, request.length.to_s)
55
+ http = HTTPClient.new
56
+ http.post(options.apiurl, request, headers)
57
+ end
58
+
59
+ def ebay_request_headers(call_name, request_length)
60
+ {
61
+ 'X-EBAY-API-CALL-NAME' => call_name,
62
+ 'X-EBAY-API-COMPATIBILITY-LEVEL' => X_EBAY_API_COMPATIBILITY_LEVEL,
63
+ 'X-EBAY-API-DEV-NAME' => options.devid,
64
+ 'X-EBAY-API-APP-NAME' => options.appid,
65
+ 'X-EBAY-API-CERT-NAME' => options.certid,
66
+ 'X-EBAY-API-SITEID' => options.siteid,
67
+ 'Content-Type' => X_EBAY_API_REQUEST_CONTENT_TYPE,
68
+ 'Content-Length' => request_length
69
+ }
70
+ end
71
+
72
+ end
@@ -0,0 +1,3 @@
1
+ require 'omniauth-ebay/version'
2
+ require 'ebay_api'
3
+ require 'omniauth/strategies/ebay'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Ebay
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,71 @@
1
+ require 'omniauth'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Ebay
6
+ include OmniAuth::Strategy
7
+ include EbayAPI
8
+
9
+ args [:runame, :devid, :appid, :certid, :siteid, :apiurl]
10
+ option :name, "ebay"
11
+ option :runame, nil
12
+ option :devid, nil
13
+ option :appid, nil
14
+ option :certid, nil
15
+ option :siteid, nil
16
+ option :apiurl, nil
17
+
18
+ uid { raw_info['EIASToken'] }
19
+ info do
20
+ {
21
+ :ebay_id => raw_info['UserID'],
22
+ :ebay_token => @auth_token,
23
+ :email => raw_info['Email']
24
+ }
25
+ end
26
+
27
+ extra do
28
+ {
29
+ :return_to => request.params["return_to"]
30
+ }
31
+ end
32
+
33
+ #1: We'll get to the request_phase by accessing /auth/ebay
34
+ #2: Request from eBay a SessionID
35
+ #3: Redirect to eBay Login URL with the RUName and SessionID
36
+ def request_phase
37
+ session_id = generate_session_id
38
+ redirect ebay_login_url(session_id)
39
+ end
40
+
41
+ #4: We'll get to the callback phase by setting our accept/reject URL in the ebay application settings(/auth/ebay/callback)
42
+ #5: Request an eBay Auth Token with the returned username&secret_id parameters.
43
+ #6: Request the user info from eBay
44
+ def callback_phase
45
+ @auth_token = get_auth_token(request.params["username"], request.params["sid"])
46
+ @user_info = get_user_info(@auth_token)
47
+ super
48
+ rescue Exception => ex
49
+ fail!("Failed to retrieve user info from ebay", ex)
50
+ end
51
+
52
+ def raw_info
53
+ @user_info
54
+ end
55
+
56
+ protected
57
+
58
+ def ebay_login_url(session_id)
59
+ #TODO: Refactor ruparams to receive all of the request query string
60
+ url = "#{EBAY_LOGIN_URL}?SingleSignOn&runame=#{options.runame}&sid=#{URI.escape(session_id).gsub('+', '%2B')}"
61
+ if request.params[:return_to]
62
+ url << "&ruparams=#{CGI::escape('return_to=' + request.params['return_to'])}"
63
+ end
64
+ return url
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+
71
+ OmniAuth.config.add_camelization 'ebay', 'Ebay'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-ebay/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-ebay"
7
+ s.version = OmniAuth::Ebay::VERSION
8
+ s.authors = ["Itay Adler"]
9
+ s.email = ["itayadler@gmail.com"]
10
+ s.homepage = "https://github.com/TheGiftsProject/omniauth-ebay"
11
+ s.summary = %q{OmniAuth strategy for eBay}
12
+ s.description = %q{In this gem you will find an OmniAuth eBay strategy that is compliant with the Open eBay Apps API.
13
+ You can read all about it here: [Open eBay Apps Developers Zone](http://developer.ebay.com/DevZone/open-ebay-apps/Concepts/OpeneBayUGDev.html)}
14
+
15
+ s.rubyforge_project = "omniauth-ebay"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_runtime_dependency 'omniauth', '~> 1.0'
23
+ s.add_development_dependency 'rspec', '~> 2.7'
24
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-ebay
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Itay Adler
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-29 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: omniauth
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 1
31
+ - 0
32
+ version: "1.0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 13
44
+ segments:
45
+ - 2
46
+ - 7
47
+ version: "2.7"
48
+ type: :development
49
+ version_requirements: *id002
50
+ description: |-
51
+ In this gem you will find an OmniAuth eBay strategy that is compliant with the Open eBay Apps API.
52
+ You can read all about it here: [Open eBay Apps Developers Zone](http://developer.ebay.com/DevZone/open-ebay-apps/Concepts/OpeneBayUGDev.html)
53
+ email:
54
+ - itayadler@gmail.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - lib/ebay_api.rb
67
+ - lib/omniauth-ebay.rb
68
+ - lib/omniauth-ebay/version.rb
69
+ - lib/omniauth/strategies/ebay.rb
70
+ - omniauth-ebay.gemspec
71
+ homepage: https://github.com/TheGiftsProject/omniauth-ebay
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options: []
76
+
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project: omniauth-ebay
100
+ rubygems_version: 1.8.17
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: OmniAuth strategy for eBay
104
+ test_files: []
105
+