authkeeper 0.1.5 → 0.1.7

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: cc7ae5d07c1884c346b471c2544044d042579ca4da69350887b654ab3b27a404
4
- data.tar.gz: ede7994f9a7449091488b9a0fcd5ecb7d42496bf1094b327500a7e24a2070f2f
3
+ metadata.gz: 4df1a975a6ed32b2e3c7a1c7371796e8112db93c7fe74cac15a7aaf7bb8d3d21
4
+ data.tar.gz: 65d219ac4b2d153c3846dd4c70a9cacb5798ba6c41b2aea76ab9e749c61138e1
5
5
  SHA512:
6
- metadata.gz: 8e27b133c53d951fba9dc9c8167b908ebea118eaf0289915e8d8ef4318621b07f2be929a5d9a54bbadd6f169cc0db22be60a69a318ae825d2c90b5c69786367e
7
- data.tar.gz: 4a2729b12b89b87f14d4be182c9b444c4dfe2a39fc95ec8bdea3edf9c29881d5e782695e89a8c8bad1487985d1258b6c942d92329222d95ad4e720861cb2d2e9
6
+ metadata.gz: bb12a72dbace108366d05d6051183dbe651bbc0e92eb5d8365bdec4f5e5d1b23b110cf8c3c9880e4ea1415be7a7331241f1bd7fef776197c811196852ae79e0e
7
+ data.tar.gz: d9db1df5121f1c583f94a74c97915038bc0ae3154a775adb7e8abe11649134bc9951ada4b975d50a91a65aacb944f1eb1e93e25eeb3bfd06dc24a89041fdf680
@@ -3,7 +3,6 @@
3
3
  module Authkeeper
4
4
  class JwtEncoder
5
5
  HMAC_SECRET = Rails.application.secret_key_base
6
- EXPIRATION_SECONDS = 604_800 # 1.week
7
6
 
8
7
  def encode(payload:, secret: HMAC_SECRET)
9
8
  JWT.encode(modify_payload(payload), secret)
@@ -18,8 +17,14 @@ module Authkeeper
18
17
  def modify_payload(payload)
19
18
  payload.merge!(
20
19
  random: SecureRandom.hex,
21
- exp: DateTime.now.to_i + EXPIRATION_SECONDS
20
+ exp: DateTime.now.to_i + token_expiration_seconds
22
21
  )
23
22
  end
23
+
24
+ private
25
+
26
+ def token_expiration_seconds
27
+ @token_expiration_seconds ||= Authkeeper.configuration.token_expiration_seconds
28
+ end
24
29
  end
25
30
  end
@@ -3,7 +3,7 @@
3
3
  module Authkeeper
4
4
  module VkAuthApi
5
5
  class Client < HttpService::Client
6
- include Requests::FetchAccessToken
6
+ include Requests::AccessToken
7
7
  include Requests::Info
8
8
 
9
9
  BASE_URL = 'https://id.vk.com/'
@@ -5,7 +5,7 @@ require 'uri'
5
5
  module Authkeeper
6
6
  module VkAuthApi
7
7
  module Requests
8
- module FetchAccessToken
8
+ module AccessToken
9
9
  def fetch_access_token(client_id:, redirect_url:, device_id:, code:, state:, code_verifier:)
10
10
  post(
11
11
  path: 'oauth2/auth',
@@ -23,6 +23,22 @@ module Authkeeper
23
23
  }
24
24
  )
25
25
  end
26
+
27
+ def refresh_access_token(client_id:, refresh_token:, device_id:, state:)
28
+ post(
29
+ path: 'oauth2/auth',
30
+ body: URI.encode_www_form({
31
+ grant_type: 'refresh_token',
32
+ client_id: client_id,
33
+ device_id: device_id,
34
+ refresh_token: refresh_token,
35
+ state: state
36
+ }),
37
+ headers: {
38
+ 'Content-Type' => 'application/x-www-form-urlencoded'
39
+ }
40
+ )
41
+ end
26
42
  end
27
43
  end
28
44
  end
@@ -17,7 +17,7 @@ module Authkeeper
17
17
  # "expires_in" => 3600,
18
18
  # "user_id" => 176780000,
19
19
  # "state" => "ce4a09792e2cc8065a96074906709765",
20
- # "scope" => "vkid.personal_info email"
20
+ # "scope" => "vkid.personal_info email phone ads"
21
21
  # }
22
22
 
23
23
  user_info = fetch_user_info(auth_info['access_token'])
@@ -36,7 +36,7 @@ module Authkeeper
36
36
 
37
37
  {
38
38
  result: {
39
- auth_info: auth_info.symbolize_keys,
39
+ auth_info: auth_info.symbolize_keys.merge(device_id: params[:device_id]),
40
40
  user_info: {
41
41
  uid: user_info.dig('user', 'user_id'),
42
42
  provider: 'vk',
@@ -5,6 +5,7 @@ module Authkeeper
5
5
  InitializeError = Class.new(StandardError)
6
6
 
7
7
  attr_accessor :user_model, :user_session_model, :access_token_name, :domain, :fallback_url_session_name, :omniauth_providers
8
+ :token_expiration_seconds
8
9
  attr_reader :omniauth_configs
9
10
 
10
11
  def initialize
@@ -17,6 +18,8 @@ module Authkeeper
17
18
 
18
19
  @omniauth_providers = []
19
20
  @omniauth_configs = {}
21
+
22
+ @token_expiration_seconds = 18_144_000 # 30.days
20
23
  end
21
24
 
22
25
  def validate
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Authkeeper
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.7'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authkeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdanov Anton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-02 00:00:00.000000000 Z
11
+ date: 2025-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -53,7 +53,7 @@ files:
53
53
  - app/lib/authkeeper/google_auth_api/requests/fetch_access_token.rb
54
54
  - app/lib/authkeeper/jwt_encoder.rb
55
55
  - app/lib/authkeeper/vk_auth_api/client.rb
56
- - app/lib/authkeeper/vk_auth_api/requests/fetch_access_token.rb
56
+ - app/lib/authkeeper/vk_auth_api/requests/access_token.rb
57
57
  - app/lib/authkeeper/vk_auth_api/requests/info.rb
58
58
  - app/lib/authkeeper/yandex_api/client.rb
59
59
  - app/lib/authkeeper/yandex_api/requests/info.rb