yol_sso 0.0.6 → 0.0.7

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
  SHA256:
3
- metadata.gz: 598864578d8e9723f9c0e1ec90166d902354daa4c1170dd0765352e93d56a980
4
- data.tar.gz: 62395714806da64948fc6ca03c44df5b3d720bffc9cca2fdfbd598d4bf222a20
3
+ metadata.gz: 6c00ab5470c95cea4324c2192ce597d64d7cb9fca9c5f0079c1f2af4c7343cff
4
+ data.tar.gz: 06f6cab80b32b46708aadc39fe36be196cfb76983890b0935fa470dd46367f3a
5
5
  SHA512:
6
- metadata.gz: c509d8f4b312375bc9e33a80d3b3c1e09d5a40582dea081ed01637d9cdc1cd3dcbfe8d3f26f8871e442356690bb51dece50bf5e5430a916c157c550348ecdf58
7
- data.tar.gz: 68ad61782b91acceb2caf1eb2fa0e8adbfc5c1d66880433d1824b1d2c2f76b4f8f9892ee890f2b63a396bdfb96927a361ce656a8b6c7350e43ded4ce172c361e
6
+ metadata.gz: 6c8a267e43b8777af1ecd405c55c6d109a080b505f97d109ebf276c28eea4c12aa2894f02aca7cebfbf2378f09d2a5f14d04dc7e553ff37cb99973efb8f8eb0e
7
+ data.tar.gz: 44eb1da4613ae4d808e10420ad0a97d48a1c70554b42134fd873b06dd75d9022b237aadccbd08ed55929cd72518569a1a60daf2af324b45d0da7c0b8807ed2ef
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yol_sso (0.0.6)
4
+ yol_sso (0.0.7)
5
5
  multi_xml
6
6
  nokogiri
7
7
  roxml
@@ -8,12 +8,13 @@ module YolSso
8
8
  include Connection::Message
9
9
  include Connection::User
10
10
 
11
- attr_accessor :host, :agentid, :redis
11
+ attr_accessor :host, :agentid, :redis, :corpsecret
12
12
 
13
13
  def initialize(options = {})
14
14
  @host = options[:host] || YolSso.configuration.host
15
15
  @agentid = options[:agentid] || YolSso.configuration.agentid
16
16
  @redis = options[:redis] || YolSso.configuration.redis
17
+ @corpsecret = options[:corpsecret] || YolSso.configuration.corpsecret
17
18
  end
18
19
  end
19
20
  end
@@ -18,20 +18,28 @@ module YolSso
18
18
  handle_res(res)
19
19
  end
20
20
 
21
+ def http_get(path, params)
22
+ uri = URI.join(host, path)
23
+ req = Net::HTTP.new(uri.host, uri.port)
24
+ header = {'token': get_access_token}
25
+ req.use_ssl = true if uri.scheme == 'https'
26
+ uri.query = URI.encode_www_form(params)
27
+ res = req.get("#{uri.path}?#{uri.query}", header)
28
+ handle_res(res)
29
+ end
30
+
21
31
  def get_access_token
22
32
  if redis.nil?
23
- access_token_res = get_token(corpid, secret)
24
- access_token = access_token_res["access_token"] rescue nil
33
+ access_token = get_token(corpsecret)
25
34
  else
26
- access_token = redis.get("qywx_access_token")
35
+ access_token = redis.get("sso_access_token")
27
36
  if access_token.nil?
28
- access_token_res = get_token(corpid, secret)
29
- access_token = access_token_res["access_token"] rescue nil
37
+ access_token = get_token(corpsecret)
30
38
  if access_token.nil?
31
- raise Exception.new("QyWeixin access token authorize false, corpid: #{corpid}")
39
+ raise Exception.new("Sso access token authorize false, corpsecret: #{corpsecret}")
32
40
  else
33
- redis.set("qywx_access_token", access_token)
34
- redis.expire("qywx_access_token", 7200)
41
+ redis.set("sso_access_token", access_token)
42
+ redis.expire("sso_access_token", 7200)
35
43
  end
36
44
  end
37
45
  end
@@ -40,12 +48,8 @@ module YolSso
40
48
 
41
49
  private
42
50
 
43
- def get_token(app_id, app_secret)
44
- http_get(token_url(app_id, app_secret))
45
- end
46
-
47
- def token_url(corpid, secret)
48
- "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=#{corpid}&corpsecret=#{secret}"
51
+ def get_token(corpsecret)
52
+ JWT.encode({exp: (Time.now+7200).to_i}, corpsecret, 'HS256') rescue nil
49
53
  end
50
54
 
51
55
  def handle_res(res)
@@ -5,6 +5,10 @@ module YolSso
5
5
  JSON.parse(redis.get("userinfo_#{userid}")) rescue nil
6
6
  end
7
7
 
8
+ def get_users(params)
9
+ http_get(users_path, params)
10
+ end
11
+
8
12
  def get_menus(userid)
9
13
  JSON.parse(redis.get("menus_#{agentid}_#{userid}")) rescue nil
10
14
  end
@@ -15,8 +19,8 @@ module YolSso
15
19
 
16
20
  private
17
21
 
18
- def send_url
19
- "#{host}messages"
22
+ def users_path
23
+ "open_api/users"
20
24
  end
21
25
  end
22
26
  end
@@ -1,7 +1,7 @@
1
1
  module YolSso
2
2
  class Configuration
3
3
 
4
- OPTIONS = [:host, :agentid, :redis].freeze
4
+ OPTIONS = [:host, :agentid, :redis, :corpsecret].freeze
5
5
 
6
6
  attr_accessor :host
7
7
 
@@ -9,5 +9,7 @@ module YolSso
9
9
 
10
10
  attr_accessor :redis
11
11
 
12
+ attr_accessor :corpsecret
13
+
12
14
  end
13
15
  end
@@ -1,3 +1,3 @@
1
1
  module YolSso
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yol_sso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - luojie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-09 00:00:00.000000000 Z
11
+ date: 2021-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler