omniauth-geekpark 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 484872d3d03863a03bc5f43d937425f472c1c433
4
- data.tar.gz: e9825002eaaddf0db70ac2bd042c183fe27e5167
3
+ metadata.gz: 5d85ef49526a5e0081670f8db93fde4f426a2d60
4
+ data.tar.gz: f31ac87bbb88591241e2814c4388a4433c40d1f8
5
5
  SHA512:
6
- metadata.gz: a7cfa51d0998b6add02cd6bdf006eea1329995032e7c08f8cc1273813874376e887ca63c38f8fef49a610566077630cbdb3a23ad5a2fe81cc31423eac2d509c9
7
- data.tar.gz: 2bb0944037864d082bae7fcf65a1e9089cdc7206ffcce0180c90bfb82eaa40876e525e302394c425d9b17b152544f23aa0898c5190fa7761ea51927b73a77536
6
+ metadata.gz: 27b0a527fc75555aef50b14db55a287ba2b27627810445c975e200b6b4a50ab62cca12d01a576d4c4ff5970fd4f32581e0432d54a08e29bc286fa4b0db281157
7
+ data.tar.gz: 0824aaf3f4cc853e034187bc5b25a4e22094f8bb8156001b1e648f012f58a84a02255213039325f3632b85be99fc36a0c9c1df18b3bab2c5e272c645a7c09ce4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- omniauth-geekpark (0.2.1)
4
+ omniauth-geekpark (1.0.4)
5
5
  omniauth (~> 1.0)
6
6
  omniauth-oauth2 (= 1.3.1)
7
7
 
@@ -43,7 +43,7 @@ GEM
43
43
  rb-inotify (>= 0.9.7)
44
44
  lumberjack (1.0.10)
45
45
  method_source (0.8.2)
46
- multi_json (1.12.0)
46
+ multi_json (1.12.1)
47
47
  multi_xml (0.5.5)
48
48
  multipart-post (2.0.0)
49
49
  nenv (0.3.0)
@@ -111,4 +111,4 @@ DEPENDENCIES
111
111
  webmock (~> 1.24, >= 1.24.2)
112
112
 
113
113
  BUNDLED WITH
114
- 1.12.3
114
+ 1.12.4
@@ -4,4 +4,5 @@ require 'omniauth-oauth2'
4
4
  require 'patch/omniauth-oauth2'
5
5
  require 'omniauth/strategies/geekpark'
6
6
  require 'omniauth/strategies/wechat'
7
+ require 'omniauth/strategies/wechat_service'
7
8
  require 'omniauth/strategies/weibo'
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module GeekPark
3
- VERSION = '1.0.4'
3
+ VERSION = '1.0.5'
4
4
  end
5
5
  end
@@ -3,7 +3,7 @@ module OmniAuth
3
3
  class WeChat < OmniAuth::Strategies::OAuth2
4
4
  option :client_options, {
5
5
  site: 'https://api.weixin.qq.com',
6
- authorize_url: 'https://open.weixin.qq.com/connect/oauth2/authorize',
6
+ authorize_url: 'https://open.weixin.qq.com/connect/qrconnect',
7
7
  token_url: 'https://api.weixin.qq.com/sns/oauth2/access_token',
8
8
  }
9
9
 
@@ -42,7 +42,7 @@ module OmniAuth
42
42
  appid: options.client_id,
43
43
  redirect_uri: callback_url,
44
44
  response_type: 'code',
45
- scope: 'snsapi_userinfo',
45
+ scope: request.params['scope'] || 'snsapi_login',
46
46
  })
47
47
  if OmniAuth.config.test_mode
48
48
  @env ||= {}
@@ -0,0 +1,92 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ class WeChatService < OmniAuth::Strategies::OAuth2
4
+ option :client_options, {
5
+ site: 'https://api.weixin.qq.com',
6
+ authorize_url: 'https://open.weixin.qq.com/connect/oauth2/authorize',
7
+ token_url: 'https://api.weixin.qq.com/sns/oauth2/access_token',
8
+ }
9
+
10
+ option :provider_ignores_state, true
11
+
12
+ uid { raw_info['unionid'] }
13
+
14
+ info do
15
+ {
16
+ nickname: raw_info['nickname'],
17
+ city: raw_info['city'],
18
+ avatar: raw_info['headimgurl']
19
+ }
20
+ end
21
+
22
+ def raw_info
23
+ @raw_info ||= begin
24
+ response = access_token.get(
25
+ '/sns/userinfo',
26
+ { params: { access_token: access_token.token,
27
+ openid: access_token['openid'],
28
+ lang: 'zh-CN' },
29
+ parse: :json }
30
+ ).parsed
31
+ log :debug, response
32
+ response
33
+ end
34
+ end
35
+
36
+ def request_phase
37
+ redirect client.authorize_url(authorize_params)+'#wechat_redirect'
38
+ end
39
+
40
+ def authorize_params
41
+ params = options.authorize_params.merge({
42
+ appid: options.client_id,
43
+ redirect_uri: callback_url,
44
+ response_type: 'code',
45
+ state: request.params['state'],
46
+ scope: request.params['scope'] || 'snsapi_userinfo'
47
+ })
48
+ if OmniAuth.config.test_mode
49
+ @env ||= {}
50
+ @env["rack.session"] ||= {}
51
+ end
52
+ unless options.provider_ignores_state
53
+ params[:state] = SecureRandom.hex(24)
54
+ session["omniauth.state"] = params[:state]
55
+ end
56
+ params
57
+ end
58
+
59
+ def token_params
60
+ { appid: options.client_id, secret: options.client_secret }
61
+ end
62
+
63
+ def callback_phase
64
+ if request.params['state'].match(/\Ahttps?:\/\/(.*\.)?geekpark\.net\/.*\z/)
65
+ env['omniauth.redirect'] = {
66
+ callback_url: request.params['state'],
67
+ code: request.params['code']
68
+ }
69
+ call_app!
70
+ else
71
+ super
72
+ end
73
+ end
74
+
75
+ protected
76
+
77
+ def build_access_token
78
+ request_params = {
79
+ appid: options.client_id,
80
+ secret: options.client_secret,
81
+ code: request.params['code'],
82
+ grant_type: 'authorization_code',
83
+ parse: :json
84
+ }
85
+ client.get_token(request_params, {mode: :query})
86
+ end
87
+
88
+ end
89
+ end
90
+ end
91
+
92
+ OmniAuth.config.add_camelization('wechatservice', 'WeChatService')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-geekpark
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - HaoYunfei
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-05-27 00:00:00.000000000 Z
12
+ date: 2016-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth
@@ -121,6 +121,7 @@ files:
121
121
  - lib/omniauth-geekpark/version.rb
122
122
  - lib/omniauth/strategies/geekpark.rb
123
123
  - lib/omniauth/strategies/wechat.rb
124
+ - lib/omniauth/strategies/wechat_service.rb
124
125
  - lib/omniauth/strategies/weibo.rb
125
126
  - lib/patch/omniauth-oauth2.rb
126
127
  - omniauth-geekpark.gemspec