authkeeper 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/authkeeper/omniauth_callbacks_controller.rb +7 -1
- data/app/helpers/authkeeper/application_helper.rb +6 -1
- data/app/lib/authkeeper/vk_auth_api/client.rb +14 -0
- data/app/lib/authkeeper/vk_auth_api/requests/fetch_access_token.rb +29 -0
- data/app/lib/authkeeper/vk_auth_api/requests/info.rb +19 -0
- data/app/services/authkeeper/providers/vk.rb +72 -0
- data/lib/authkeeper/container.rb +2 -0
- data/lib/authkeeper/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fb703b887c4415e68a9ed91bea0a41cf1c682ccf20742d18c26700205f37a72
|
4
|
+
data.tar.gz: f9ff63172357aab12de6252c5c58a764ec9e354921fc9199826d0876778ecbfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 633d17c8e59833d357dca0861cbfef908813a8668102ddff1e6760cc6e9aa3dc1fe249b3f7a194f4324d7c1722b97ba2684c2ed14b88993afea003943630bb73
|
7
|
+
data.tar.gz: 902eef36cfcee239262871e13d1fd1eace8eca90f0b99449541d31ae46e94002c8943cc492d2b823861e2b2dff1c04f44bb5b51a68cef236b6a8a88553eb16c6
|
@@ -12,6 +12,7 @@ module Authkeeper
|
|
12
12
|
TELEGRAM = 'telegram'
|
13
13
|
GOOGLE = 'google'
|
14
14
|
YANDEX = 'yandex'
|
15
|
+
VK = 'vk'
|
15
16
|
|
16
17
|
skip_before_action :verify_authenticity_token
|
17
18
|
skip_before_action :authenticate, only: %i[create]
|
@@ -49,7 +50,12 @@ module Authkeeper
|
|
49
50
|
end
|
50
51
|
|
51
52
|
def auth
|
52
|
-
@auth ||=
|
53
|
+
@auth ||=
|
54
|
+
provider_service(params[:provider]).call(params: params.merge(oauth_data))[:result]
|
55
|
+
end
|
56
|
+
|
57
|
+
def oauth_data
|
58
|
+
Rails.cache.read("oauth_data_#{params[:state]}") || {}
|
53
59
|
end
|
54
60
|
|
55
61
|
def provider_service(provider)
|
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
module Authkeeper
|
4
4
|
module ApplicationHelper
|
5
|
-
def omniauth_link(provider)
|
5
|
+
def omniauth_link(provider, oauth_data=nil)
|
6
6
|
case provider
|
7
7
|
when :github then github_oauth_link
|
8
8
|
when :gitlab then gitlab_oauth_link
|
9
9
|
when :google then google_oauth_link
|
10
10
|
when :yandex then yandex_oauth_link
|
11
|
+
when :vk then vk_oauth_link(oauth_data)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
@@ -29,6 +30,10 @@ module Authkeeper
|
|
29
30
|
def yandex_oauth_link
|
30
31
|
"https://oauth.yandex.ru/authorize?response_type=code&client_id=#{value(:yandex, :client_id)}"
|
31
32
|
end
|
33
|
+
|
34
|
+
def vk_oauth_link(oauth_data)
|
35
|
+
"https://id.vk.com/authorize?scope=email&response_type=code&client_id=#{value(:vk, :client_id)}&code_challenge=#{oauth_data[:code_challenge]}&code_challenge_method=S256&redirect_uri=#{value(:vk, :redirect_url)}&state=#{oauth_data[:state]}"
|
36
|
+
end
|
32
37
|
# rubocop: enable Layout/LineLength
|
33
38
|
|
34
39
|
def value(provider, key)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Authkeeper
|
4
|
+
module VkAuthApi
|
5
|
+
class Client < HttpService::Client
|
6
|
+
include Requests::FetchAccessToken
|
7
|
+
include Requests::Info
|
8
|
+
|
9
|
+
BASE_URL = 'https://id.vk.com/'
|
10
|
+
|
11
|
+
option :url, default: proc { BASE_URL }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Authkeeper
|
6
|
+
module VkAuthApi
|
7
|
+
module Requests
|
8
|
+
module FetchAccessToken
|
9
|
+
def fetch_access_token(client_id:, redirect_url:, device_id:, code:, state:, code_verifier:)
|
10
|
+
post(
|
11
|
+
path: 'oauth2/auth',
|
12
|
+
body: URI.encode_www_form({
|
13
|
+
grant_type: 'authorization_code',
|
14
|
+
client_id: client_id,
|
15
|
+
device_id: device_id,
|
16
|
+
code: code,
|
17
|
+
state: state,
|
18
|
+
redirect_uri: redirect_url,
|
19
|
+
code_verifier: code_verifier
|
20
|
+
}),
|
21
|
+
headers: {
|
22
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
23
|
+
}
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Authkeeper
|
4
|
+
module VkAuthApi
|
5
|
+
module Requests
|
6
|
+
module Info
|
7
|
+
def info(access_token:, client_id:)
|
8
|
+
post(
|
9
|
+
path: 'oauth2/user_info',
|
10
|
+
body: {
|
11
|
+
access_token: access_token,
|
12
|
+
client_id: client_id
|
13
|
+
}
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Authkeeper
|
4
|
+
module Providers
|
5
|
+
class Vk
|
6
|
+
include AuthkeeperDeps[
|
7
|
+
auth_client: 'api.vk.auth_client'
|
8
|
+
]
|
9
|
+
|
10
|
+
def call(params: {})
|
11
|
+
auth_info = fetch_auth_info(params)
|
12
|
+
# {
|
13
|
+
# "refresh_token" => "vk2.a.",
|
14
|
+
# "access_token" => "vk2.a.",
|
15
|
+
# "id_token" => "",
|
16
|
+
# "token_type" => "Bearer",
|
17
|
+
# "expires_in" => 3600,
|
18
|
+
# "user_id" => 176780000,
|
19
|
+
# "state" => "ce4a09792e2cc8065a96074906709765",
|
20
|
+
# "scope" => "vkid.personal_info email"
|
21
|
+
# }
|
22
|
+
|
23
|
+
user_info = fetch_user_info(auth_info['access_token'])
|
24
|
+
# {
|
25
|
+
# "user" => {
|
26
|
+
# "user_id" => "176780000",
|
27
|
+
# "first_name" => "",
|
28
|
+
# "last_name" => "",
|
29
|
+
# "avatar" => "",
|
30
|
+
# "email" => "",
|
31
|
+
# "sex" => 2,
|
32
|
+
# "verified" => false,
|
33
|
+
# "birthday" => "01.01.2000"
|
34
|
+
# }
|
35
|
+
# }
|
36
|
+
|
37
|
+
{
|
38
|
+
result: {
|
39
|
+
auth_info: auth_info.symbolize_keys,
|
40
|
+
user_info: {
|
41
|
+
uid: user_info.dig('user', 'user_id'),
|
42
|
+
provider: 'vk',
|
43
|
+
email: user_info.dig('user', 'email'),
|
44
|
+
phone_number: "+#{user_info.dig('user', 'phone')}"
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def fetch_auth_info(params)
|
53
|
+
auth_client.fetch_access_token(
|
54
|
+
client_id: omniauth_config[:client_id],
|
55
|
+
redirect_url: omniauth_config[:redirect_url],
|
56
|
+
device_id: params[:device_id],
|
57
|
+
code: params[:code],
|
58
|
+
state: params[:state],
|
59
|
+
code_verifier: params[:code_verifier]
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
def fetch_user_info(access_token)
|
64
|
+
auth_client.info(access_token: access_token, client_id: omniauth_config[:client_id])
|
65
|
+
end
|
66
|
+
|
67
|
+
def omniauth_config
|
68
|
+
@omniauth_config ||= Authkeeper.configuration.omniauth_configs[:vk]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/authkeeper/container.rb
CHANGED
@@ -25,12 +25,14 @@ module Authkeeper
|
|
25
25
|
register('api.google.client') { Authkeeper::GoogleApi::Client.new }
|
26
26
|
register('api.yandex.auth_client') { Authkeeper::YandexAuthApi::Client.new }
|
27
27
|
register('api.yandex.client') { Authkeeper::YandexApi::Client.new }
|
28
|
+
register('api.vk.auth_client') { Authkeeper::VkAuthApi::Client.new }
|
28
29
|
|
29
30
|
register('services.providers.github') { Authkeeper::Providers::Github.new }
|
30
31
|
register('services.providers.gitlab') { Authkeeper::Providers::Gitlab.new }
|
31
32
|
register('services.providers.telegram') { Authkeeper::Providers::Telegram.new }
|
32
33
|
register('services.providers.google') { Authkeeper::Providers::Google.new }
|
33
34
|
register('services.providers.yandex') { Authkeeper::Providers::Yandex.new }
|
35
|
+
register('services.providers.vk') { Authkeeper::Providers::Vk.new }
|
34
36
|
|
35
37
|
register('services.fetch_session') { Authkeeper::FetchSessionService.new }
|
36
38
|
register('services.generate_token') { Authkeeper::GenerateTokenService.new }
|
data/lib/authkeeper/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.3
|
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-11-
|
11
|
+
date: 2024-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -52,6 +52,9 @@ files:
|
|
52
52
|
- app/lib/authkeeper/google_auth_api/client.rb
|
53
53
|
- app/lib/authkeeper/google_auth_api/requests/fetch_access_token.rb
|
54
54
|
- app/lib/authkeeper/jwt_encoder.rb
|
55
|
+
- app/lib/authkeeper/vk_auth_api/client.rb
|
56
|
+
- app/lib/authkeeper/vk_auth_api/requests/fetch_access_token.rb
|
57
|
+
- app/lib/authkeeper/vk_auth_api/requests/info.rb
|
55
58
|
- app/lib/authkeeper/yandex_api/client.rb
|
56
59
|
- app/lib/authkeeper/yandex_api/requests/info.rb
|
57
60
|
- app/lib/authkeeper/yandex_auth_api/client.rb
|
@@ -64,6 +67,7 @@ files:
|
|
64
67
|
- app/services/authkeeper/providers/gitlab.rb
|
65
68
|
- app/services/authkeeper/providers/google.rb
|
66
69
|
- app/services/authkeeper/providers/telegram.rb
|
70
|
+
- app/services/authkeeper/providers/vk.rb
|
67
71
|
- app/services/authkeeper/providers/yandex.rb
|
68
72
|
- app/views/layouts/authkeeper/application.html.erb
|
69
73
|
- config/routes.rb
|