adsk_auth_service 1.0.23 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -2
- data/adsk_auth_service.gemspec +4 -5
- data/lib/adsk_auth_service.rb +1 -1
- data/lib/services/auth_service.rb +7 -10
- metadata +4 -5
- data/lib/utils/net_util.rb +0 -95
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 907324dac0c36867e32fd63368528a56726fed22
|
4
|
+
data.tar.gz: ab1484824bcd901561a394216db9a5801d052921
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79e733a19761c1baa179e23ea395b98890b1256af54d6ef6d428c95ffe6551e9847fb9234808c17f52d0909e60bed71947111efe1ee506fb77a0946a91da87f1
|
7
|
+
data.tar.gz: b0e3e5b534412deb91c46dcd17a805657050fe8c77c83aee44835a1d3ef5c7a0d44933d8c377727d615fd005d11a794f0359a0d8a01144fd5bc62a576a66efb2
|
data/Gemfile
CHANGED
data/adsk_auth_service.gemspec
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'adsk_auth_service'
|
3
|
-
s.version = '1.0
|
3
|
+
s.version = '1.1.0'
|
4
4
|
s.summary = "Autodesk second phase token retrieval"
|
5
5
|
s.description = "A gem for Autodesk 2-phase authentication service."
|
6
6
|
s.authors = ['Linh Chau']
|
7
7
|
s.email = 'chauhonglinh@gmail.com'
|
8
8
|
s.files = [
|
9
|
-
'./Gemfile', './adsk_auth_service.gemspec',
|
9
|
+
'./Gemfile', './adsk_auth_service.gemspec',
|
10
10
|
'lib/adsk_auth_service.rb',
|
11
|
-
'lib/services/auth_service.rb'
|
12
|
-
'lib/utils/net_util.rb',
|
11
|
+
'lib/services/auth_service.rb'
|
13
12
|
]
|
14
13
|
s.homepage = 'https://github.com/linhchauatl/adsk_auth_service'
|
15
14
|
s.license = 'MIT'
|
16
15
|
s.add_runtime_dependency 'config_service'
|
17
|
-
s.add_runtime_dependency '
|
16
|
+
s.add_runtime_dependency 'rest-client'
|
18
17
|
|
19
18
|
s.add_development_dependency 'rspec', '~> 3.1'
|
20
19
|
end
|
data/lib/adsk_auth_service.rb
CHANGED
@@ -10,7 +10,7 @@ rescue Exception => error
|
|
10
10
|
end
|
11
11
|
|
12
12
|
|
13
|
-
['services'
|
13
|
+
['services'].each do |sub_path|
|
14
14
|
load_gem_lib(sub_path)
|
15
15
|
rb_files = Dir.glob("#{File.expand_path('.')}/lib/#{sub_path}/*.rb")
|
16
16
|
rb_files.each { |rb_file| require rb_file }
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'active_support/core_ext'
|
3
|
-
|
3
|
+
require 'rest-client'
|
4
4
|
|
5
5
|
class AuthService
|
6
6
|
class << self
|
7
7
|
def load_config
|
8
|
-
@@config ||= ConfigService.load_config('auth_keys.yml')[ConfigService.environment]
|
8
|
+
@@config ||= ConfigService.load_config('auth_keys.yml')[ConfigService.environment]
|
9
9
|
end
|
10
10
|
|
11
11
|
def set_config(options = {})
|
@@ -20,16 +20,13 @@ class AuthService
|
|
20
20
|
url = options['url'] || @@config['url']
|
21
21
|
key = options['consumer_key'] || @@config['consumer_key']
|
22
22
|
secret = options['consumer_secret'] || @@config['consumer_secret']
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
"client_id=#{key}&client_secret=#{secret}&grant_type=client_credentials",
|
28
|
-
{ headers: {'Content-Type' => 'application/x-www-form-urlencoded', 'grant_type' => 'client_credentials'} }).body
|
29
|
-
)
|
23
|
+
response = RestClient.post(url,
|
24
|
+
"client_id=#{key}&client_secret=#{secret}&grant_type=client_credentials",
|
25
|
+
{'Content-Type' => 'application/x-www-form-urlencoded', 'grant_type' => 'client_credentials'} )
|
26
|
+
JSON.parse(response)
|
30
27
|
end
|
31
28
|
|
32
29
|
end
|
33
30
|
|
34
31
|
load_config
|
35
|
-
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adsk_auth_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Linh Chau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: config_service
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rest-client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -62,7 +62,6 @@ files:
|
|
62
62
|
- "./adsk_auth_service.gemspec"
|
63
63
|
- lib/adsk_auth_service.rb
|
64
64
|
- lib/services/auth_service.rb
|
65
|
-
- lib/utils/net_util.rb
|
66
65
|
homepage: https://github.com/linhchauatl/adsk_auth_service
|
67
66
|
licenses:
|
68
67
|
- MIT
|
@@ -83,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
82
|
version: '0'
|
84
83
|
requirements: []
|
85
84
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
85
|
+
rubygems_version: 2.6.7
|
87
86
|
signing_key:
|
88
87
|
specification_version: 4
|
89
88
|
summary: Autodesk second phase token retrieval
|
data/lib/utils/net_util.rb
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'net/https'
|
2
|
-
require 'active_support'
|
3
|
-
require 'faraday'
|
4
|
-
|
5
|
-
class NetUtil
|
6
|
-
READ_TIMEOUT = 600 # 10 minutes
|
7
|
-
RETRY_TIMES = 3
|
8
|
-
WAIT_TIME = 5 # Wait for 5 seconds before retry
|
9
|
-
|
10
|
-
class << self
|
11
|
-
|
12
|
-
# This method performs GET, PUT and POST requests to web services
|
13
|
-
# Call it like this:
|
14
|
-
# response = NetUtil.call_web_services(url) <= This will perform a GET, with url provided by the caller
|
15
|
-
# response = NetUtil.call_web_services(url, 'post', doc) <= This will perform a POST, doc is the data to post, can be REXML::Document or XML String
|
16
|
-
# In the case of GET, the returned XML data is 'response'
|
17
|
-
# In the case of POST and PUT, the returned XML data is 'response.body'
|
18
|
-
def call_webservices(url, method_name = 'get', data = '', options = { headers: {'Content-Type' => 'application/json'} })
|
19
|
-
method_name = method_name.to_s.downcase
|
20
|
-
try_time = 0
|
21
|
-
begin
|
22
|
-
NetUtil.send("do_#{method_name}", {url: url, data: data}.merge(options))
|
23
|
-
rescue StandardError => error
|
24
|
-
try_time += 1
|
25
|
-
if try_time > RETRY_TIMES
|
26
|
-
puts ("\n#{Time.now} Unrecoverable error in NetUtil.call_webservices: "\
|
27
|
-
"#{error}\n#{error.backtrace.join("\n")}\n")
|
28
|
-
# It is an unrecoverable error, throw the exception back, don't suppress it.
|
29
|
-
raise "Unrecoverable error calling web services.\nURL: #{url}.\nError message: #{error.message}."
|
30
|
-
end
|
31
|
-
|
32
|
-
puts ("NetUtil.call_webservices #{url}:\nError happens: #{error}. Try #{try_time} time(s).")
|
33
|
-
sleep(WAIT_TIME)
|
34
|
-
retry
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def do_get(options)
|
39
|
-
do_get_headers = build_header(options)
|
40
|
-
params = options[:params] || {}
|
41
|
-
do_get_url = options[:url]
|
42
|
-
do_get_uri = URI.parse(do_get_url)
|
43
|
-
conn = Faraday.new(:url => do_get_url) do |faraday|
|
44
|
-
faraday.adapter Faraday.default_adapter
|
45
|
-
end
|
46
|
-
|
47
|
-
response = conn.get do |req|
|
48
|
-
req.url do_get_uri.path, params
|
49
|
-
do_get_headers.each { |key, value| req.headers[key] = value}
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def do_post(options)
|
54
|
-
run_p(options, :post)
|
55
|
-
end
|
56
|
-
|
57
|
-
def do_put(options)
|
58
|
-
run_p(options, :put)
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
def run_p(options, method_name)
|
63
|
-
data = options[:data].to_s
|
64
|
-
|
65
|
-
headers = build_header(options)
|
66
|
-
url = options[:url]
|
67
|
-
uri = URI.parse(url)
|
68
|
-
req = Net::HTTP.new(uri.host, uri.port)
|
69
|
-
req = set_ssl(req, url)
|
70
|
-
|
71
|
-
req.read_timeout = READ_TIMEOUT
|
72
|
-
req.open_timeout = READ_TIMEOUT
|
73
|
-
|
74
|
-
return req.send(method_name, uri.path, data, headers)
|
75
|
-
end
|
76
|
-
|
77
|
-
def build_header(options)
|
78
|
-
headers = (options[:headers] || { 'Content-Type' => 'application/json' }).dup
|
79
|
-
conntent_type = ( headers['Content-Type'].nil? )? 'application/json' : headers['Content-Type']
|
80
|
-
headers.delete('Content-Type')
|
81
|
-
{'Content-Type' => conntent_type}.merge(headers)
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
def set_ssl(request, url)
|
86
|
-
if url.start_with? 'https'
|
87
|
-
request.use_ssl = true
|
88
|
-
request.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
89
|
-
end
|
90
|
-
request
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
|