yol_sso 0.0.3 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +68 -0
- data/Gemfile.lock +3 -3
- data/lib/yol_sso/client.rb +8 -7
- data/lib/yol_sso/connections/base.rb +18 -14
- data/lib/yol_sso/connections/user.rb +27 -0
- data/lib/yol_sso/models/configuration.rb +5 -1
- data/lib/yol_sso/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c00ab5470c95cea4324c2192ce597d64d7cb9fca9c5f0079c1f2af4c7343cff
|
4
|
+
data.tar.gz: 06f6cab80b32b46708aadc39fe36be196cfb76983890b0935fa470dd46367f3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c8a267e43b8777af1ecd405c55c6d109a080b505f97d109ebf276c28eea4c12aa2894f02aca7cebfbf2378f09d2a5f14d04dc7e553ff37cb99973efb8f8eb0e
|
7
|
+
data.tar.gz: 44eb1da4613ae4d808e10420ad0a97d48a1c70554b42134fd873b06dd75d9022b237aadccbd08ed55929cd72518569a1a60daf2af324b45d0da7c0b8807ed2ef
|
data/.gitignore
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
.idea
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
*.DS_Store
|
5
|
+
*.swp
|
6
|
+
Gemfile.lock
|
7
|
+
GemfileLocal
|
8
|
+
GemfileLocal.lock
|
9
|
+
|
10
|
+
# Ignore all logfiles and tempfiles.
|
11
|
+
/log/*
|
12
|
+
/tmp/*
|
13
|
+
!/log/.keep
|
14
|
+
!/tmp/.keep
|
15
|
+
|
16
|
+
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
|
17
|
+
config/initializers/secret_token.rb
|
18
|
+
config/master.key
|
19
|
+
|
20
|
+
# Only include if you have production secrets in this file, which is no longer a Rails default
|
21
|
+
# config/secrets.yml
|
22
|
+
|
23
|
+
# dotenv
|
24
|
+
# TODO Comment out this rule if environment variables can be committed
|
25
|
+
.env
|
26
|
+
|
27
|
+
## Environment normalization:
|
28
|
+
/.bundle
|
29
|
+
/vendor/bundle
|
30
|
+
|
31
|
+
# these should all be checked in to normalize the environment:
|
32
|
+
# Gemfile.lock, .ruby-version, .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
36
|
+
|
37
|
+
# if using bower-rails ignore default bower_components path bower.json files
|
38
|
+
/vendor/assets/bower_components
|
39
|
+
*.bowerrc
|
40
|
+
bower.json
|
41
|
+
|
42
|
+
# Ignore pow environment settings
|
43
|
+
.powenv
|
44
|
+
|
45
|
+
# Ignore Byebug command history file.
|
46
|
+
.byebug_history
|
47
|
+
|
48
|
+
# Ignore node_modules
|
49
|
+
node_modules/
|
50
|
+
|
51
|
+
# Ignore precompiled javascript packs
|
52
|
+
/public/packs
|
53
|
+
/public/packs-test
|
54
|
+
/public/assets
|
55
|
+
|
56
|
+
# Ignore yarn files
|
57
|
+
/yarn-error.log
|
58
|
+
yarn-debug.log*
|
59
|
+
.yarn-integrity
|
60
|
+
|
61
|
+
# Ignore uploaded files in development
|
62
|
+
/storage/*
|
63
|
+
!/storage/.keep
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
yol_sso (0.0.
|
4
|
+
yol_sso (0.0.7)
|
5
5
|
multi_xml
|
6
6
|
nokogiri
|
7
7
|
roxml
|
@@ -20,11 +20,11 @@ GEM
|
|
20
20
|
concurrent-ruby (~> 1.0)
|
21
21
|
minitest (5.14.4)
|
22
22
|
multi_xml (0.6.0)
|
23
|
-
nokogiri (1.
|
23
|
+
nokogiri (1.12.4-x86_64-darwin)
|
24
24
|
racc (~> 1.4)
|
25
25
|
racc (1.5.2)
|
26
26
|
rake (13.0.1)
|
27
|
-
roxml (4.
|
27
|
+
roxml (4.2.0)
|
28
28
|
activesupport (>= 4.0)
|
29
29
|
nokogiri (>= 1.3.3)
|
30
30
|
thread_safe (0.3.6)
|
data/lib/yol_sso/client.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
require "monitor"
|
2
2
|
require "redis"
|
3
3
|
require 'digest/md5'
|
4
|
-
module YolSso
|
4
|
+
module YolSso
|
5
5
|
class Client
|
6
6
|
|
7
7
|
include Connection::Base
|
8
8
|
include Connection::Message
|
9
|
+
include Connection::User
|
9
10
|
|
10
|
-
attr_accessor :host
|
11
|
-
|
12
|
-
attr_accessor :agentid
|
11
|
+
attr_accessor :host, :agentid, :redis, :corpsecret
|
13
12
|
|
14
13
|
def initialize(options = {})
|
15
|
-
@host = options[:host] ||
|
16
|
-
@agentid = options[:agentid] ||
|
14
|
+
@host = options[:host] || YolSso.configuration.host
|
15
|
+
@agentid = options[:agentid] || YolSso.configuration.agentid
|
16
|
+
@redis = options[:redis] || YolSso.configuration.redis
|
17
|
+
@corpsecret = options[:corpsecret] || YolSso.configuration.corpsecret
|
17
18
|
end
|
18
19
|
end
|
19
|
-
end
|
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
|
-
|
24
|
-
access_token = access_token_res["access_token"] rescue nil
|
33
|
+
access_token = get_token(corpsecret)
|
25
34
|
else
|
26
|
-
access_token = redis.get("
|
35
|
+
access_token = redis.get("sso_access_token")
|
27
36
|
if access_token.nil?
|
28
|
-
|
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("
|
39
|
+
raise Exception.new("Sso access token authorize false, corpsecret: #{corpsecret}")
|
32
40
|
else
|
33
|
-
redis.set("
|
34
|
-
redis.expire("
|
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(
|
44
|
-
|
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)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module YolSso
|
2
|
+
module Connection
|
3
|
+
module User
|
4
|
+
def get_user(userid)
|
5
|
+
JSON.parse(redis.get("userinfo_#{userid}")) rescue nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_users(params)
|
9
|
+
http_get(users_path, params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_menus(userid)
|
13
|
+
JSON.parse(redis.get("menus_#{agentid}_#{userid}")) rescue nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_api_list(userid)
|
17
|
+
JSON.parse(redis.get("accesses_#{agentid}_#{userid}")) rescue nil
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def users_path
|
23
|
+
"open_api/users"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
module YolSso
|
2
2
|
class Configuration
|
3
3
|
|
4
|
-
OPTIONS = [:host, :agentid].freeze
|
4
|
+
OPTIONS = [:host, :agentid, :redis, :corpsecret].freeze
|
5
5
|
|
6
6
|
attr_accessor :host
|
7
7
|
|
8
8
|
attr_accessor :agentid
|
9
9
|
|
10
|
+
attr_accessor :redis
|
11
|
+
|
12
|
+
attr_accessor :corpsecret
|
13
|
+
|
10
14
|
end
|
11
15
|
end
|
data/lib/yol_sso/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2021-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- ".DS_Store"
|
91
|
+
- ".gitignore"
|
91
92
|
- Gemfile
|
92
93
|
- Gemfile.lock
|
93
94
|
- LICENSE.txt
|
@@ -98,6 +99,7 @@ files:
|
|
98
99
|
- lib/yol_sso/connection.rb
|
99
100
|
- lib/yol_sso/connections/base.rb
|
100
101
|
- lib/yol_sso/connections/message.rb
|
102
|
+
- lib/yol_sso/connections/user.rb
|
101
103
|
- lib/yol_sso/helpers/pkcs7_encoder.rb
|
102
104
|
- lib/yol_sso/helpers/prpcrypt.rb
|
103
105
|
- lib/yol_sso/models/configuration.rb
|