omniauth-alipay-oauth2 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: faea30d49e2bdfa5bd5a67dd705dadb809bd2e5a
4
+ data.tar.gz: 031159221b8f48904bb6bae166201fe18b364cd8
5
+ SHA512:
6
+ metadata.gz: 321e97da1c8faef3bf178dc75b5f4731022e8b29a72e254301a578422ff71da2bf313bb62f6af58e04a178e95b1aa5fec79ceea8d81a3124e193274d64fe157c
7
+ data.tar.gz: a0b266404b05d0c6d18f003dcbd9bf2ce205c0c781799306c9374ec39c2ef3ae377ff3a88a3ff1385cdad0b2483566a0fc2fb8405ab49e8a9c9cf7e0565f0534
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-alipay.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-alipay-oauth2 (0.1.0)
5
+ alipay (~> 0.15.0)
6
+ omniauth
7
+ omniauth-oauth2
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ alipay (0.15.0)
13
+ faraday (0.12.2)
14
+ multipart-post (>= 1.2, < 3)
15
+ hashie (3.5.6)
16
+ jwt (1.5.6)
17
+ multi_json (1.12.2)
18
+ multi_xml (0.6.0)
19
+ multipart-post (2.0.0)
20
+ oauth2 (1.4.0)
21
+ faraday (>= 0.8, < 0.13)
22
+ jwt (~> 1.0)
23
+ multi_json (~> 1.3)
24
+ multi_xml (~> 0.5)
25
+ rack (>= 1.2, < 3)
26
+ omniauth (1.7.1)
27
+ hashie (>= 3.4.6, < 3.6.0)
28
+ rack (>= 1.6.2, < 3)
29
+ omniauth-oauth2 (1.4.0)
30
+ oauth2 (~> 1.0)
31
+ omniauth (~> 1.2)
32
+ rack (2.0.3)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ omniauth-alipay-oauth2!
39
+
40
+ BUNDLED WITH
41
+ 1.15.4
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ The Artistic License 2.0
2
+
3
+ Copyright (c) 2014 Yohansun
4
+
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ This license establishes the terms under which a given free software
11
+ Package may be copied, modified, distributed, and/or redistributed.
12
+ The intent is that the Copyright Holder maintains some artistic
13
+ control over the development of that Package while still keeping the
14
+ Package available as open source and free software.
15
+
16
+ You are always permitted to make arrangements wholly outside of this
17
+ license directly with the Copyright Holder of a given Package. If the
18
+ terms of this license do not permit the full use that you propose to
19
+ make of the Package, you should contact the Copyright Holder and seek
20
+ a different licensing arrangement.
21
+
22
+ Definitions
23
+
24
+ "Copyright Holder" means the individual(s) or organization(s)
25
+ named in the copyright notice for the entire Package.
26
+
27
+ "Contributor" means any party that has contributed code or other
28
+ material to the Package, in accordance with the Copyright Holder's
29
+ procedures.
30
+
31
+ "You" and "your" means any person who would like to copy,
32
+ distribute, or modify the Package.
33
+
34
+ "Package" means the collection of files distributed by the
35
+ Copyright Holder, and derivatives of that collection and/or of
36
+ those files. A given Package may consist of either the Standard
37
+ Version, or a Modified Version.
38
+
39
+ "Distribute" means providing a copy of the Package or making it
40
+ accessible to anyone else, or in the case of a company or
41
+ organization, to others outside of your company or organization.
42
+
43
+ "Distributor Fee" means any fee that you charge for Distributing
44
+ this Package or providing support for this Package to another
45
+ party. It does not mean licensing fees.
46
+
47
+ "Standard Version" refers to the Package if it has not been
48
+ modified, or has been modified only in ways explicitly requested
49
+ by the Copyright Holder.
50
+
51
+ "Modified Version" means the Package, if it has been changed, and
52
+ such changes were not explicitly requested by the Copyright
53
+ Holder.
54
+
55
+ "Original License" means this Artistic License as Distributed with
56
+ the Standard Version of the Package, in its current version or as
57
+ it may be modified by The Perl Foundation in the future.
58
+
59
+ "Source" form means the source code, documentation source, and
60
+ configuration files for the Package.
61
+
62
+ "Compiled" form means the compiled bytecode, object code, binary,
63
+ or any other form resulting from mechanical transformation or
64
+ translation of the Source form.
65
+
66
+
67
+ Permission for Use and Modification Without Distribution
68
+
69
+ (1) You are permitted to use the Standard Version and create and use
70
+ Modified Versions for any purpose without restriction, provided that
71
+ you do not Distribute the Modified Version.
72
+
73
+
74
+ Permissions for Redistribution of the Standard Version
75
+
76
+ (2) You may Distribute verbatim copies of the Source form of the
77
+ Standard Version of this Package in any medium without restriction,
78
+ either gratis or for a Distributor Fee, provided that you duplicate
79
+ all of the original copyright notices and associated disclaimers. At
80
+ your discretion, such verbatim copies may or may not include a
81
+ Compiled form of the Package.
82
+
83
+ (3) You may apply any bug fixes, portability changes, and other
84
+ modifications made available from the Copyright Holder. The resulting
85
+ Package will still be considered the Standard Version, and as such
86
+ will be subject to the Original License.
87
+
88
+
89
+ Distribution of Modified Versions of the Package as Source
90
+
91
+ (4) You may Distribute your Modified Version as Source (either gratis
92
+ or for a Distributor Fee, and with or without a Compiled form of the
93
+ Modified Version) provided that you clearly document how it differs
94
+ from the Standard Version, including, but not limited to, documenting
95
+ any non-standard features, executables, or modules, and provided that
96
+ you do at least ONE of the following:
97
+
98
+ (a) make the Modified Version available to the Copyright Holder
99
+ of the Standard Version, under the Original License, so that the
100
+ Copyright Holder may include your modifications in the Standard
101
+ Version.
102
+
103
+ (b) ensure that installation of your Modified Version does not
104
+ prevent the user installing or running the Standard Version. In
105
+ addition, the Modified Version must bear a name that is different
106
+ from the name of the Standard Version.
107
+
108
+ (c) allow anyone who receives a copy of the Modified Version to
109
+ make the Source form of the Modified Version available to others
110
+ under
111
+
112
+ (i) the Original License or
113
+
114
+ (ii) a license that permits the licensee to freely copy,
115
+ modify and redistribute the Modified Version using the same
116
+ licensing terms that apply to the copy that the licensee
117
+ received, and requires that the Source form of the Modified
118
+ Version, and of any works derived from it, be made freely
119
+ available in that license fees are prohibited but Distributor
120
+ Fees are allowed.
121
+
122
+
123
+ Distribution of Compiled Forms of the Standard Version
124
+ or Modified Versions without the Source
125
+
126
+ (5) You may Distribute Compiled forms of the Standard Version without
127
+ the Source, provided that you include complete instructions on how to
128
+ get the Source of the Standard Version. Such instructions must be
129
+ valid at the time of your distribution. If these instructions, at any
130
+ time while you are carrying out such distribution, become invalid, you
131
+ must provide new instructions on demand or cease further distribution.
132
+ If you provide valid instructions or cease distribution within thirty
133
+ days after you become aware that the instructions are invalid, then
134
+ you do not forfeit any of your rights under this license.
135
+
136
+ (6) You may Distribute a Modified Version in Compiled form without
137
+ the Source, provided that you comply with Section 4 with respect to
138
+ the Source of the Modified Version.
139
+
140
+
141
+ Aggregating or Linking the Package
142
+
143
+ (7) You may aggregate the Package (either the Standard Version or
144
+ Modified Version) with other packages and Distribute the resulting
145
+ aggregation provided that you do not charge a licensing fee for the
146
+ Package. Distributor Fees are permitted, and licensing fees for other
147
+ components in the aggregation are permitted. The terms of this license
148
+ apply to the use and Distribution of the Standard or Modified Versions
149
+ as included in the aggregation.
150
+
151
+ (8) You are permitted to link Modified and Standard Versions with
152
+ other works, to embed the Package in a larger work of your own, or to
153
+ build stand-alone binary or bytecode versions of applications that
154
+ include the Package, and Distribute the result without restriction,
155
+ provided the result does not expose a direct interface to the Package.
156
+
157
+
158
+ Items That are Not Considered Part of a Modified Version
159
+
160
+ (9) Works (including, but not limited to, modules and scripts) that
161
+ merely extend or make use of the Package, do not, by themselves, cause
162
+ the Package to be a Modified Version. In addition, such works are not
163
+ considered parts of the Package itself, and are not subject to the
164
+ terms of this license.
165
+
166
+
167
+ General Provisions
168
+
169
+ (10) Any use, modification, and distribution of the Standard or
170
+ Modified Versions is governed by this Artistic License. By using,
171
+ modifying or distributing the Package, you accept this license. Do not
172
+ use, modify, or distribute the Package, if you do not accept this
173
+ license.
174
+
175
+ (11) If your Modified Version has been derived from a Modified
176
+ Version made by someone other than you, you are nevertheless required
177
+ to ensure that your Modified Version complies with the requirements of
178
+ this license.
179
+
180
+ (12) This license does not grant you the right to use any trademark,
181
+ service mark, tradename, or logo of the Copyright Holder.
182
+
183
+ (13) This license includes the non-exclusive, worldwide,
184
+ free-of-charge patent license to make, have made, use, offer to sell,
185
+ sell, import and otherwise transfer the Package with respect to any
186
+ patent claims licensable by the Copyright Holder that are necessarily
187
+ infringed by the Package. If you institute patent litigation
188
+ (including a cross-claim or counterclaim) against any party alleging
189
+ that the Package constitutes direct or contributory patent
190
+ infringement, then this Artistic License to you shall terminate on the
191
+ date that such litigation is filed.
192
+
193
+ (14) Disclaimer of Warranty:
194
+ THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
195
+ IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
196
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
197
+ NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL
198
+ LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL
199
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
200
+ DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF
201
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ omniauth-alipay
2
+ ===============
3
+
4
+ Alipay OAuth2 Strategy for OmniAuth.
5
+
6
+ Support connecting Alipay account to third-party APP and website.
7
+ Read the Alipay docs for more details:
8
+ [App支付宝登录](https://docs.open.alipay.com/218#), [网站支付宝登录](https://docs.open.alipay.com/263)
9
+
10
+ ## Installing
11
+
12
+ Add to your `Gemfile`:
13
+
14
+ ```ruby
15
+ gem 'omniauth-alipay', path: 'FX-HAO/omniauth-alipay'
16
+ ```
17
+
18
+ Then `bundle install`.
19
+
20
+ ## Usage
21
+
22
+ Adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
23
+
24
+ ```ruby
25
+ Rails.application.config.middleware.use OmniAuth::Builder do
26
+ provider :alipay, 'your_app_id', File.read('rsa_private_key.pem'), 'alipay_public_key'
27
+ end
28
+ ```
29
+
30
+ Read the OmniAuth docs for detailed instructions: https://github.com/intridea/omniauth.
31
+
32
+ ## Sandbox
33
+
34
+ Developing in sandbox environment. See: [关于沙箱](https://docs.open.alipay.com/263/105809#s4)
35
+
36
+ ```ruby
37
+ Rails.application.config.middleware.use OmniAuth::Builder do
38
+ provider :alipay, 'your_app_id', File.read('rsa_private_key.pem'), 'alipay_public_key',
39
+ client_options: {
40
+ authorize_url: 'https://openauth.alipaydev.com/oauth2/publicAppAuthorize.htm',
41
+ token_url: 'https://openauth.alipaydev.com/oauth2/token',
42
+ url: 'https://openapi.alipaydev.com/gateway.do'
43
+ }
44
+ end
45
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,120 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Alipay < OmniAuth::Strategies::OAuth2
6
+ class Error < ::OAuth2::Error
7
+ attr_reader :response_json, :sub_code, :sub_msg
8
+
9
+ def initialize(response_json)
10
+ @response_json = response_json
11
+ error_response = response_json['error_response']
12
+ @code = error_response['code']
13
+ @description = error_response['msg']
14
+ @sub_code = error_response['sub_code']
15
+ @sub_msg = error_response['sub_msg']
16
+ end
17
+
18
+ def error_message
19
+ @response_json['error_response'].to_json
20
+ end
21
+
22
+ def message
23
+ error_message
24
+ end
25
+ end
26
+
27
+ option :name, 'alipay'
28
+
29
+ args [:client_id, :app_private_key, :alipay_public_key]
30
+
31
+ option :app_private_key, nil
32
+ option :alipay_public_key, nil
33
+
34
+ option :client_options, {
35
+ authorize_url: 'https://openauth.alipay.com/oauth2/publicAppAuthorize.htm',
36
+ token_url: 'https://openauth.alipay.com/oauth2/token',
37
+ url: 'https://openapi.alipay.com/gateway.do'
38
+ }
39
+
40
+ uid { raw_info['user_id'] }
41
+
42
+ info do
43
+ {
44
+ avatar: raw_info['avatar'],
45
+ user_type_value: raw_info['user_type_value'],
46
+ user_status: raw_info['user_type_value'],
47
+ gender: raw_info['gender'],
48
+ is_certified: raw_info['is_certified'],
49
+ province: raw_info['province'],
50
+ city: raw_info['city'],
51
+ is_student_certified: raw_info['is_student_certified'],
52
+ alipay_user_id: raw_info['alipay_user_id'],
53
+ nickname: raw_info['nick_name']
54
+ }
55
+ end
56
+
57
+ extra do
58
+ {raw_info: raw_info}
59
+ end
60
+
61
+ def request_phase
62
+ params = client.auth_code.authorize_params.merge(redirect_uri: callback_url).merge(authorize_params)
63
+ params['app_id'] = params.delete('client_id')
64
+ params['scope'] = 'auth_user'
65
+ params['state'] = 'init'
66
+ params.delete('response_type')
67
+ redirect client.authorize_url(params)
68
+ end
69
+
70
+ def raw_info
71
+ return @raw_info if @raw_info
72
+ alipay_client = ::Alipay::Client.new(
73
+ url: options.client_options.url,
74
+ app_id: options.client_id,
75
+ app_private_key: options.app_private_key,
76
+ alipay_public_key: options.alipay_public_key,
77
+ sign_type: 'RSA'
78
+ )
79
+ params = alipay_client.sdk_execute(
80
+ method: 'alipay.user.info.share',
81
+ auth_token: access_token.token
82
+ )
83
+ response = client.request(:get, options.client_options.url, params: Rack::Utils.parse_nested_query(params))
84
+ data = build_response_json(response.body)
85
+ @raw_info = data['alipay_user_info_share_response']
86
+ end
87
+
88
+ protected
89
+
90
+ def build_access_token
91
+ alipay_client = ::Alipay::Client.new(
92
+ url: options.client_options.url,
93
+ app_id: options.client_id,
94
+ app_private_key: options.app_private_key,
95
+ alipay_public_key: options.alipay_public_key,
96
+ sign_type: 'RSA'
97
+ )
98
+ params = alipay_client.sdk_execute(
99
+ method: 'alipay.system.oauth.token',
100
+ grant_type: 'authorization_code',
101
+ code: request.params['auth_code']
102
+ )
103
+ response = client.request(:get, options.client_options.url, params: Rack::Utils.parse_nested_query(params))
104
+ data = build_response_json(response.body)
105
+ ::OAuth2::AccessToken.from_hash(client, data['alipay_system_oauth_token_response'].merge(deep_symbolize(options.auth_token_params)))
106
+ end
107
+
108
+ private
109
+
110
+ # @param response_body [String] The response body
111
+ # @return [Hash] A hash of the parsed body
112
+ def build_response_json(response_body)
113
+ data = JSON.parse(response_body)
114
+ raise 'Cannot parse response body' unless data.is_a?(Hash)
115
+ raise Error.new(data) if data.has_key?('error_response')
116
+ data
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Alipay
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'omniauth-alipay/version'
2
+ require 'omniauth/strategies/alipay'
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-alipay/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'omniauth-alipay-oauth2'
8
+ spec.version = Omniauth::Alipay::VERSION
9
+ spec.authors = ['Fuxin Hao']
10
+ spec.email = ['haofxpro@gmail.com']
11
+ spec.homepage = 'https://github.com/FX-HAO/omniauth-alipay'
12
+ spec.description = 'Facebook OAuth2 Strategy for OmniAuth'
13
+ spec.summary = spec.description
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
+ else
20
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
21
+ 'public gem pushes.'
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
25
+ f.match(%r{^(test|spec|features)/})
26
+ end
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+
31
+ spec.required_ruby_version = '>= 2.0'
32
+
33
+ spec.add_dependency 'omniauth'
34
+ spec.add_dependency 'omniauth-oauth2'
35
+ spec.add_dependency 'alipay', '~> 0.15.0'
36
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-alipay-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fuxin Hao
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: alipay
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.15.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.15.0
55
+ description: Facebook OAuth2 Strategy for OmniAuth
56
+ email:
57
+ - haofxpro@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - lib/omniauth-alipay.rb
69
+ - lib/omniauth-alipay/version.rb
70
+ - lib/omniauth/strategies/alipay.rb
71
+ - omniauth-alipay.gemspec
72
+ homepage: https://github.com/FX-HAO/omniauth-alipay
73
+ licenses: []
74
+ metadata:
75
+ allowed_push_host: https://rubygems.org
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '2.0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.5.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Facebook OAuth2 Strategy for OmniAuth
96
+ test_files: []