omniauth-geekpark 0.2.1 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7243dc2c492c7a98d0950cc0900cfc2793a10de
4
- data.tar.gz: 36a747bece1db45a3babea4d55dea936f17803b9
3
+ metadata.gz: 68ef9ed52f2beb5aaef7a219f08b0fb78e78e71d
4
+ data.tar.gz: ffe2ec5ac882ebad416d8d854e399ca7b3be2727
5
5
  SHA512:
6
- metadata.gz: cecd4f0962dd5b233ae1278bf77e9199fd585d2f2c80e0bb49d4e88c3eb2845d9cf5ae5f13effdc039e3681f3d7083e96a27a8991dc04573982d93946a048eda
7
- data.tar.gz: a8df5babd21c547f65a1617b877cb86f4d56955cf1f249021a54bfab7be7d833822e12d75a0ee4c85cac1ce54cd2b355f5cc1fcb7b5b540a7e978245871b4bd6
6
+ metadata.gz: bb3a4e60903eef221e8712ebccf046f26f6a31adee1dd473b0d84ba88abb72efd424a3fff202bd1c2da6bd69d23bfcea0b970d10f55cc0cce2d9590d7025cbab
7
+ data.tar.gz: bc6c385a26bd7ef5e8eb143fc9c48a4ba8a21699244fd1774d356727f4db08881d4badea25b9080e78dd1ee32f52922916e5b984fcdcb90366aea9d3a241c71a
data/README.md CHANGED
@@ -21,3 +21,10 @@ use OmniAuth::Builder do
21
21
  end
22
22
  ```
23
23
 
24
+ ### Helper
25
+ ```
26
+ class User < ActiveRecord::Base
27
+ include OmniAuth::GeekPark::Helper
28
+ end
29
+ ```
30
+ see more at code
@@ -2,29 +2,26 @@ module OmniAuth
2
2
  module Strategies
3
3
  class GeekPark < OmniAuth::Strategies::OAuth2
4
4
  option :client_options, {
5
- site: 'http://www.geekpark.net',
6
- authorize_url: 'http://www.geekpark.net/oauth/authorize',
7
- token_url: 'http://www.geekpark.net/oauth/token'
5
+ site: 'https://account.geekpark.net',
6
+ authorize_url: '/oauth2/authorize',
7
+ token_url: '/oauth2/token'
8
8
  }
9
9
 
10
- uid { raw_info['uuid'] }
10
+ uid { raw_info['id'] }
11
11
 
12
12
  info do
13
13
  {
14
- username: raw_info['username'],
15
- realname: raw_info['realname'],
16
- email: raw_info['email'],
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
- mygeekpark_open_id: raw_info['mygeekpark_open_id'],
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
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module GeekPark
3
- VERSION = "0.2.1"
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -1,4 +1,5 @@
1
1
  require 'omniauth-geekpark/version'
2
+ require 'omniauth-geekpark/helper'
2
3
  require 'omniauth-oauth2'
3
4
  require 'patch/omniauth-oauth2'
4
5
  require 'omniauth/strategies/geekpark'
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.2.1
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-13 00:00:00.000000000 Z
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