rail-locator-api 0.0.19 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cdebdc95542d15a2e79b2c3dba9c0c6dc88add41d32b4da3eeb6d8c42bf5807e
4
- data.tar.gz: 73c42e81cf2a1672f61d8ba1136de88d581dd806ec6e18c1f00f28b23e7ce5a8
3
+ metadata.gz: 1cd04f690b1b9b0c7efd7d0a1e08699381e219de12d1575d4b46cd382d46f19e
4
+ data.tar.gz: aa985811938780f4fa6c0d3f3e7a8257a6e6fbe846ae47b69da5147f10a3b05d
5
5
  SHA512:
6
- metadata.gz: b780cdd84ba22c71cc4c5ba263b43696cc08123cc784b5f497b50add24e174c51abeb514f6738c42e251da9f23ffa9aa26ab846eff183c59940d9a8b75cc63c1
7
- data.tar.gz: 9ed1b8490a6c516ee2a5714d48d40750cfad2c5e5a0dbaae214a4aa4f63b991c05de75a01600c0edcb772bc72ee61eb480a5dce121861c4086af9facfd26acc3
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 == :api_key
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"
@@ -1,3 +1,3 @@
1
1
  module RailLocatorApi
2
- VERSION = "0.0.19"
2
+ VERSION = "0.0.22"
3
3
  end
@@ -9,10 +9,24 @@ require 'rail-locator-api/response'
9
9
  module RailLocatorApi
10
10
  class << self
11
11
  def generate_access_token
12
- response = Faraday.post(
13
- RailLocatorApi.keycloak_token_url,
14
- "grant_type=#{RailLocatorApi.keycloak_grant_type}&client_id=#{RailLocatorApi.keycloak_client_id}&username=#{RailLocatorApi.api_user_email}&password=#{RailLocatorApi.api_user_password}")
15
- JSON.parse(response.body)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rail-locator-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Osetrov