omniauth-geekpark 0.2.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/omniauth/strategies/geekpark.rb +10 -13
- data/lib/omniauth-geekpark/helper.rb +32 -0
- data/lib/omniauth-geekpark/version.rb +1 -1
- data/lib/omniauth-geekpark.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68ef9ed52f2beb5aaef7a219f08b0fb78e78e71d
|
4
|
+
data.tar.gz: ffe2ec5ac882ebad416d8d854e399ca7b3be2727
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb3a4e60903eef221e8712ebccf046f26f6a31adee1dd473b0d84ba88abb72efd424a3fff202bd1c2da6bd69d23bfcea0b970d10f55cc0cce2d9590d7025cbab
|
7
|
+
data.tar.gz: bc6c385a26bd7ef5e8eb143fc9c48a4ba8a21699244fd1774d356727f4db08881d4badea25b9080e78dd1ee32f52922916e5b984fcdcb90366aea9d3a241c71a
|
data/README.md
CHANGED
@@ -2,29 +2,26 @@ module OmniAuth
|
|
2
2
|
module Strategies
|
3
3
|
class GeekPark < OmniAuth::Strategies::OAuth2
|
4
4
|
option :client_options, {
|
5
|
-
site: '
|
6
|
-
authorize_url: '
|
7
|
-
token_url: '
|
5
|
+
site: 'https://account.geekpark.net',
|
6
|
+
authorize_url: '/oauth2/authorize',
|
7
|
+
token_url: '/oauth2/token'
|
8
8
|
}
|
9
9
|
|
10
|
-
uid { raw_info['
|
10
|
+
uid { raw_info['id'] }
|
11
11
|
|
12
12
|
info do
|
13
13
|
{
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
company: raw_info['company'],
|
18
|
-
position: raw_info['position'],
|
19
|
-
mobile: raw_info['mobile'],
|
20
|
-
avatar: raw_info['avatar'],
|
14
|
+
nickname: raw_info['nickname'],
|
15
|
+
gender: raw_info['gender'],
|
16
|
+
city: raw_info['city'],
|
21
17
|
bio: raw_info['bio'],
|
22
|
-
|
18
|
+
position: raw_info['position'],
|
19
|
+
avatar_url: raw_info['avatar_url']
|
23
20
|
}
|
24
21
|
end
|
25
22
|
|
26
23
|
def raw_info
|
27
|
-
@raw_info ||= access_token.get('/api/v1/user').parsed
|
24
|
+
@raw_info ||= access_token.get('/api/v1/user').parsed
|
28
25
|
end
|
29
26
|
end
|
30
27
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module GeekPark
|
3
|
+
module Helper
|
4
|
+
def token
|
5
|
+
token? ? super : refresh_token!
|
6
|
+
end
|
7
|
+
|
8
|
+
def token?
|
9
|
+
self[:token].present? && (Time.current < expires_at)
|
10
|
+
end
|
11
|
+
|
12
|
+
def refresh_token!
|
13
|
+
return unless refresh_token.present?
|
14
|
+
|
15
|
+
res = Faraday.post "https://account.geekpark.net/oauth2/token" do |req|
|
16
|
+
req.body = { grant_type: 'refresh_token',
|
17
|
+
refresh_token: refresh_token,
|
18
|
+
client_id: ENV['GEEKPARK_KEY'],
|
19
|
+
client_secret: ENV['GEEKPARK_SECRET'] }
|
20
|
+
end
|
21
|
+
|
22
|
+
if res.status == 200
|
23
|
+
body = JSON.parse(res.body)
|
24
|
+
update(token: body["access_token"], expires_at: (Time.now + body['expires_in']), refresh_token: body['refresh_token'])
|
25
|
+
return body['access_token']
|
26
|
+
else
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/omniauth-geekpark.rb
CHANGED
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: 0.
|
4
|
+
version: 1.0.0
|
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-
|
12
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: omniauth
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- bin/console
|
118
118
|
- bin/setup
|
119
119
|
- lib/omniauth-geekpark.rb
|
120
|
+
- lib/omniauth-geekpark/helper.rb
|
120
121
|
- lib/omniauth-geekpark/version.rb
|
121
122
|
- lib/omniauth/strategies/geekpark.rb
|
122
123
|
- lib/omniauth/strategies/wechat.rb
|