omniauth-eleme-oauth2 0.0.1

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: 0a6595957840cb4d089c0bc2514bf6b5f167d71d
4
+ data.tar.gz: 210a6c40a9620de5966258e7a1344aba28c83d1c
5
+ SHA512:
6
+ metadata.gz: 3961463958eb7df6fdae4c15bff31bcd70a0220b53e5f7e4a7a918f1ece4337113bc0bc0270ef46635b2b4b3a320f72a4417d15c30bf42b9f36866c179a23577
7
+ data.tar.gz: d92b1f7025ffaffb40e94cd6add95b45e374934a68f0c15f8071a12543a0e81622d804263366201d154a89af6eeef541e0d6e0ff8cbfeecb8a91c13af49e9cb8
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ Omniauth-eleme-oauth2
2
+ ======================
3
+
4
+ Wechat OAuth2 Strategy for OmniAuth 1.0.
5
+
6
+ You need to get a eleme API key at: https://open.shop.ele.me/
7
+
8
+ Wechat oauth2 specification can be found at: https://open.shop.ele.me/openapi/documents/oauth
9
+
10
+ ## Installation
11
+
12
+ Add to your `Gemfile`:
13
+
14
+ ```ruby
15
+ gem "omniauth-eleme-oauth2"
16
+ ```
17
+
18
+ Then `bundle install`.
19
+
20
+
21
+ ## Usage
22
+
23
+ Here's an example for adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
24
+
25
+ ```ruby
26
+ Rails.application.config.middleware.use OmniAuth::Builder do
27
+ provider :eleme, ENV["ELEME_KEY"], ENV["ELEME_SECRET"]
28
+ end
29
+ ```
30
+
31
+ You can now access the OmniAuth Wechat OAuth2 URL: `/auth/eleme`
32
+
33
+ ## Configuration
34
+
35
+ You can configure several options, which you pass in to the `provider` method via a hash:
36
+
37
+ * `scope`: Default is "snsapi_userinfo". It can either be *snsapi_base* or *snsapi_userinfo*. When scope is "snsapi_userinfo", after eleme user is authenticated, app can query userinfo using the acquired access_token.
38
+
39
+ For devise user, you can set up scope in your devise.rb as following.
40
+
41
+ ```ruby
42
+ config.omniauth :eleme, ENV["ELEME_KEY"], ENV["ELEME_SECRET"]
43
+ ```
44
+
45
+ ## Auth Hash
46
+
47
+ Here's an example of an authentication hash available in the callback by accessing `request.env["omniauth.auth"]`:
48
+
49
+ ```ruby
50
+ {
51
+ :provider => "eleme",
52
+ :info => {
53
+ token_type: "bearer"
54
+ },
55
+ :credentials => {
56
+ :token => "access_token",
57
+ :refresh_token => "refresh_token",
58
+ :expires_in => 7200,
59
+ :expires => true
60
+ },
61
+ :extra => {}
62
+ }
63
+ ```
64
+
65
+ Also, you may need params from redirect_uri. e.g. if you access http://localhost:3000/auth/eleme?branch_id=25. Here's an example of an parameter hash available in the callback by accessing `request.env["omniauth.params"]`.:
66
+
67
+ {
68
+ branch_id: 25
69
+ }
70
+
71
+
@@ -0,0 +1,53 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Eleme < OmniAuth::Strategies::OAuth2
6
+ # Give your strategy a name.
7
+ option :name, "eleme"
8
+
9
+ option :authorize_params, {scope: "all"}
10
+ # This is where you pass the options you would pass when
11
+ # initializing your consumer from the OAuth gem.
12
+ option :client_options, {
13
+ :site => "https://open-api-sandbox.shop.ele.me",
14
+ :authorize_url => "/authorize",
15
+ :token_method => :post,
16
+ # :token_url => "http://localhost:3002/backend/shops/diandanbao/branches",
17
+ :token_url => "/token",
18
+ :auth_scheme => "basic_auth"
19
+ }
20
+
21
+ # These are called after authentication has succeeded. If
22
+ # possible, you should try to set the UID without making
23
+ # additional calls (if the user id is returned with the token
24
+ # or as a URI parameter). This may not be possible with all
25
+ # providers.
26
+ uid{ }
27
+
28
+ info do
29
+ {
30
+ token_type: access_token["token_type"]
31
+ }
32
+ end
33
+
34
+ extra do
35
+ {}
36
+ end
37
+
38
+
39
+ protected
40
+ def build_access_token
41
+ Rails.logger.info("#{client.id}:#{client.secret}")
42
+ params = {
43
+ 'client_id' => client.id,
44
+ 'code' => request.params['code'],
45
+ 'grant_type' => 'authorization_code',
46
+ 'redirect_uri' => callback_url
47
+ }.merge(token_params.to_hash(symbolize_keys: true))
48
+ response = client.get_token(params, deep_symbolize(options.auth_token_params))
49
+ response
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1 @@
1
+ require "omniauth/strategies/eleme"
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-eleme-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - neil
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-10 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: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.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: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Using OAuth2 to authenticate ele.me shop user when web resources being
56
+ viewed
57
+ email:
58
+ - wanxsb@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - README.md
64
+ - lib/omniauth-eleme-oauth2.rb
65
+ - lib/omniauth/strategies/eleme.rb
66
+ homepage: http://www.diandanbao.com
67
+ licenses: []
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements:
84
+ - none
85
+ rubyforge_project:
86
+ rubygems_version: 2.4.8
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: omniauth strategy for eleme
90
+ test_files: []