elmas 3.0.1 → 3.1.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 +4 -4
- data/Changelog.md +4 -0
- data/lib/elmas/exception.rb +5 -1
- data/lib/elmas/oauth.rb +3 -54
- data/lib/elmas/parser.rb +2 -1
- data/lib/elmas/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b17b89ef70b1b3a09cbef79f2fb3132b80ca5da223fc9ef12dbe7aead89d5a04
|
4
|
+
data.tar.gz: a18c2b4f0820792037c561238285555de12dc9b3b623e215d31ec95ac774abb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf45cd2c72c8024c6ae0ec447fabd04a42512f2d47cf64ca16225d8ce2934203b7c77578c68efd4e988b0c668ee39c7efa39d7c5e142738ff209ae6c2df49386
|
7
|
+
data.tar.gz: 8c4d887c2d65f85d1f841fa4e84a8ff2df9f367fa3214fc5077c7f45dd9d96f9c29b102a8c172287265be715dc7a21359862ce0c90b62487dccb5fc1d2a2b672
|
data/Changelog.md
CHANGED
data/lib/elmas/exception.rb
CHANGED
data/lib/elmas/oauth.rb
CHANGED
@@ -15,30 +15,10 @@ require File.expand_path("../response", __FILE__)
|
|
15
15
|
module Elmas
|
16
16
|
# rubocop:disable Metrics/ModuleLength
|
17
17
|
module OAuth
|
18
|
-
def authorize(user_name, password, options = {})
|
19
|
-
warn "[DEPRECATION] `authorize` is deprecated. Please implement your own authorization methods instead."
|
20
|
-
agent = Mechanize.new
|
21
|
-
|
22
|
-
login(agent, user_name, password, options)
|
23
|
-
allow_access(agent)
|
24
|
-
|
25
|
-
code = URI.unescape(agent.page.uri.query.split("=").last)
|
26
|
-
OauthResponse.new(get_access_token(code))
|
27
|
-
end
|
28
|
-
|
29
|
-
def refresh_authorization
|
30
|
-
warn "[DEPRECATION] `refresh_authorization` is deprecated. Please implement your own authorization methods instead."
|
31
|
-
OauthResponse.new(get_refresh_token(refresh_token)).tap do |response|
|
32
|
-
Elmas.configure do |config|
|
33
|
-
config.access_token = response.access_token
|
34
|
-
config.refresh_token = response.refresh_token
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
18
|
def authorized?
|
40
19
|
# Do a test call, return false if 401 or any error code
|
41
|
-
get("/Current/Me", no_division: true)
|
20
|
+
response = Elmas.get("/Current/Me", no_division: true)
|
21
|
+
response.results.first.present?
|
42
22
|
rescue BadRequestException
|
43
23
|
Elmas.error "Not yet authorized"
|
44
24
|
return false
|
@@ -48,17 +28,6 @@ module Elmas
|
|
48
28
|
get("/Current/Me", no_division: true).results.first.current_division
|
49
29
|
end
|
50
30
|
|
51
|
-
def auto_authorize
|
52
|
-
warn "[DEPRECATION] `auto_authorize` is deprecated. Please implement your own authorization methods instead."
|
53
|
-
Elmas.configure do |config|
|
54
|
-
config.redirect_uri = ENV["REDIRECT_URI"]
|
55
|
-
config.client_id = ENV["CLIENT_ID"]
|
56
|
-
config.client_secret = ENV["CLIENT_SECRET"]
|
57
|
-
config.access_token = Elmas.authorize(ENV["EXACT_USER_NAME"], ENV["EXACT_PASSWORD"]).access_token
|
58
|
-
config.division = Elmas.authorize_division
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
31
|
# Return URL for OAuth authorization
|
63
32
|
def authorize_url(options = {})
|
64
33
|
options[:response_type] ||= "code"
|
@@ -102,24 +71,6 @@ module Elmas
|
|
102
71
|
|
103
72
|
private
|
104
73
|
|
105
|
-
def login(agent, user_name, password, options)
|
106
|
-
# Login
|
107
|
-
agent.get(authorize_url(options)) do |page|
|
108
|
-
form = page.forms.first
|
109
|
-
form["UserNameField"] = user_name
|
110
|
-
form["PasswordField"] = password
|
111
|
-
form.click_button
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def allow_access(agent)
|
116
|
-
return if agent.page.uri.to_s.include?("getpostman")
|
117
|
-
return if agent.page.uri.to_s.include?(redirect_uri)
|
118
|
-
form = agent.page.form_with(id: "PublicOAuth2Form")
|
119
|
-
button = form.button_with(id: "AllowButton")
|
120
|
-
agent.submit(form, button)
|
121
|
-
end
|
122
|
-
|
123
74
|
def authorization_params
|
124
75
|
{
|
125
76
|
client_id: client_id
|
@@ -145,9 +96,7 @@ module Elmas
|
|
145
96
|
}
|
146
97
|
end
|
147
98
|
end
|
148
|
-
end
|
149
99
|
|
150
|
-
module Elmas
|
151
100
|
class OauthResponse < Response
|
152
101
|
def body
|
153
102
|
JSON.parse(@response.body)
|
@@ -165,4 +114,4 @@ module Elmas
|
|
165
114
|
body["refresh_token"]
|
166
115
|
end
|
167
116
|
end
|
168
|
-
end
|
117
|
+
end
|
data/lib/elmas/parser.rb
CHANGED
data/lib/elmas/version.rb
CHANGED