rail-locator-api 0.0.19 → 0.0.22
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cd04f690b1b9b0c7efd7d0a1e08699381e219de12d1575d4b46cd382d46f19e
|
4
|
+
data.tar.gz: aa985811938780f4fa6c0d3f3e7a8257a6e6fbe846ae47b69da5147f10a3b05d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f9328334ac06dfa1b3a0e1fe3ed589fb0b38f7d3fc81283118f045a1d10b3203d40599cf6f583ac26b0d9f4030d01a5ea105bcd1dba40860b1fc6eb8faea787
|
7
|
+
data.tar.gz: d630474fd87853779aedbeb257c96b9e1dc3bba7250f4d1ce5bb6365c53cb579910577beec3cf1e135ef6e2603816d6d930cf04b28bce11b345f076f2c555494
|
@@ -6,6 +6,7 @@ defaults: &defaults
|
|
6
6
|
KEYCLOAK_TOKEN_URL: "https://iam.ctm.ru/auth/realms/ctm/protocol/openid-connect/token"
|
7
7
|
KEYCLOAK_GRANT_TYPE: "password"
|
8
8
|
KEYCLOAK_CLIENT_ID: "ctm_lk"
|
9
|
+
KEYCLOAK_REDIRECT_URI: "http://yousite.ru/callback"
|
9
10
|
production:
|
10
11
|
<<: *defaults
|
11
12
|
development:
|
@@ -132,10 +132,7 @@ module RailLocatorApi
|
|
132
132
|
if self.api_auth_method == :base64
|
133
133
|
request.headers['Authorization'] = "Basic " + Base64::encode64("#{self.api_user_email}:#{self.api_user_password}")
|
134
134
|
end
|
135
|
-
if self.api_auth_method
|
136
|
-
request.headers['X-API-KEY'] = "#{self.api_key}"
|
137
|
-
end
|
138
|
-
if self.api_auth_method == :keycloak
|
135
|
+
if [:api_key, :keycloak].include?(self.api_auth_method)
|
139
136
|
request.headers['Authorization'] = "Bearer #{RailLocatorApi::Request.access_token}"
|
140
137
|
end
|
141
138
|
request.headers['User-Agent'] = "RailLocatorApi/#{RailLocatorApi::VERSION} Ruby gem"
|
data/lib/rail-locator-api.rb
CHANGED
@@ -9,10 +9,24 @@ require 'rail-locator-api/response'
|
|
9
9
|
module RailLocatorApi
|
10
10
|
class << self
|
11
11
|
def generate_access_token
|
12
|
-
|
13
|
-
RailLocatorApi.
|
14
|
-
|
15
|
-
|
12
|
+
if RailLocatorApi.keycloak_grant_type == "password"
|
13
|
+
payload = "grant_type=#{RailLocatorApi.keycloak_grant_type}&client_id=#{RailLocatorApi.keycloak_client_id}&username=#{RailLocatorApi.api_user_email}&password=#{RailLocatorApi.api_user_password}"
|
14
|
+
else
|
15
|
+
payload = "grant_type=#{RailLocatorApi.keycloak_grant_type}&client_id=#{RailLocatorApi.keycloak_client_id}&code=#{RailLocatorApi::Request.api_key}&redirect_uri=#{RailLocatorApi.keycloak_redirect_uri}"
|
16
|
+
end
|
17
|
+
|
18
|
+
connection = Faraday.new(RailLocatorApi.keycloak_token_url, proxy: nil,
|
19
|
+
ssl: { version: "TLSv1_2" }) do |faraday|
|
20
|
+
faraday.adapter Faraday.default_adapter
|
21
|
+
faraday.response :logger, ::Logger.new(STDOUT), bodies: true
|
22
|
+
end
|
23
|
+
|
24
|
+
response = connection.post RailLocatorApi.keycloak_token_url, payload do |request|
|
25
|
+
request.headers['Content-Type'] = 'application/json'
|
26
|
+
request.headers['accept'] = 'application/json'
|
27
|
+
end
|
28
|
+
|
29
|
+
JSON.parse(response.body).try(:dig, :access_token)
|
16
30
|
end
|
17
31
|
|
18
32
|
def setup
|