authkeeper 0.1.8 → 0.1.10
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/app/controllers/authkeeper/omniauth_callbacks_controller.rb +1 -0
- data/app/helpers/authkeeper/application_helper.rb +5 -0
- data/app/lib/authkeeper/discord_api/client.rb +21 -0
- data/app/lib/authkeeper/discord_api/requests/user.rb +16 -0
- data/app/lib/authkeeper/discord_auth_api/client.rb +13 -0
- data/app/lib/authkeeper/discord_auth_api/requests/fetch_access_token.rb +25 -0
- data/app/services/authkeeper/providers/discord.rb +46 -0
- data/app/services/authkeeper/providers/telegram.rb +5 -3
- data/lib/authkeeper/container.rb +3 -0
- data/lib/authkeeper/controllers/authentication.rb +11 -0
- data/lib/authkeeper/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65f8ece85bc4e6ed31e1ed3ae5b142cd2b79b7cfe2e3fdd87009e1537a37a271
|
4
|
+
data.tar.gz: e92f55f1bb92d4c2b910436650fc90aa13749f7f03d3ba3c4d0b1d6b7917d2e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8abc1c3a419e87aa6b1e3456ae22152824f9f823ef430fb7748108a2959dd78253331674e510ceef753e73107d59531bbe6a2633aad11c9b66fd43e32957bf21
|
7
|
+
data.tar.gz: a0b54c38844b41e5def8c6ac8a153cbb99c711d25c5ba5044b7c074ebc2169814c3afdcd3b06ba3ce21383a169617bfb0f5cf31b0c006948a287774d51aa8e71
|
@@ -4,6 +4,7 @@ module Authkeeper
|
|
4
4
|
module ApplicationHelper
|
5
5
|
def omniauth_link(provider, oauth_data=nil)
|
6
6
|
case provider
|
7
|
+
when :discord then discord_oauth_link
|
7
8
|
when :github then github_oauth_link
|
8
9
|
when :gitlab then gitlab_oauth_link
|
9
10
|
when :google then google_oauth_link
|
@@ -15,6 +16,10 @@ module Authkeeper
|
|
15
16
|
private
|
16
17
|
|
17
18
|
# rubocop: disable Layout/LineLength
|
19
|
+
def discord_oauth_link
|
20
|
+
"https://discord.com/oauth2/authorize?client_id=#{value(:discord, :client_id)}&response_type=code&redirect_uri=#{value(:discord, :redirect_url)}&scope=identify"
|
21
|
+
end
|
22
|
+
|
18
23
|
def github_oauth_link
|
19
24
|
"https://github.com/login/oauth/authorize?scope=user:email&response_type=code&client_id=#{value(:github, :client_id)}&redirect_uri=#{value(:github, :redirect_url)}"
|
20
25
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Authkeeper
|
4
|
+
module DiscordApi
|
5
|
+
class Client < HttpService::Client
|
6
|
+
include Requests::User
|
7
|
+
|
8
|
+
BASE_URL = 'https://discord.com/api/v10/'
|
9
|
+
|
10
|
+
option :url, default: proc { BASE_URL }
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def headers(access_token)
|
15
|
+
{
|
16
|
+
'Authorization' => "Bearer #{access_token}"
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Authkeeper
|
4
|
+
module DiscordAuthApi
|
5
|
+
class Client < HttpService::Client
|
6
|
+
include Requests::FetchAccessToken
|
7
|
+
|
8
|
+
BASE_URL = 'https://discord.com/api/v10/'
|
9
|
+
|
10
|
+
option :url, default: proc { BASE_URL }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Authkeeper
|
4
|
+
module DiscordAuthApi
|
5
|
+
module Requests
|
6
|
+
module FetchAccessToken
|
7
|
+
def fetch_access_token(client_id:, client_secret:, code:, redirect_uri:)
|
8
|
+
form_post(
|
9
|
+
path: 'oauth2/token',
|
10
|
+
body: {
|
11
|
+
grant_type: 'authorization_code',
|
12
|
+
code: code,
|
13
|
+
redirect_uri: redirect_uri,
|
14
|
+
client_id: client_id,
|
15
|
+
client_secret: client_secret
|
16
|
+
},
|
17
|
+
headers: {
|
18
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
19
|
+
}
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Authkeeper
|
4
|
+
module Providers
|
5
|
+
class Discord
|
6
|
+
include AuthkeeperDeps[
|
7
|
+
auth_client: 'api.discord.auth_client',
|
8
|
+
api_client: 'api.discord.client'
|
9
|
+
]
|
10
|
+
|
11
|
+
def call(params: {})
|
12
|
+
access_token = fetch_access_token(params[:code])
|
13
|
+
return { errors: ['Invalid code'] } unless access_token
|
14
|
+
|
15
|
+
user = fetch_user_info(access_token)
|
16
|
+
|
17
|
+
{
|
18
|
+
result: {
|
19
|
+
uid: user.dig('user', 'id').to_s,
|
20
|
+
provider: 'discord',
|
21
|
+
login: user.dig('user', 'username')
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def fetch_access_token(code)
|
29
|
+
auth_client.fetch_access_token(
|
30
|
+
client_id: omniauth_config[:client_id],
|
31
|
+
client_secret: omniauth_config[:client_secret],
|
32
|
+
redirect_uri: omniauth_config[:redirect_url],
|
33
|
+
code: code
|
34
|
+
)['access_token']
|
35
|
+
end
|
36
|
+
|
37
|
+
def fetch_user_info(access_token)
|
38
|
+
api_client.user(access_token: access_token)[:body]
|
39
|
+
end
|
40
|
+
|
41
|
+
def omniauth_config
|
42
|
+
@omniauth_config ||= Authkeeper.configuration.omniauth_configs[:discord]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -6,8 +6,8 @@ require 'base64'
|
|
6
6
|
module Authkeeper
|
7
7
|
module Providers
|
8
8
|
class Telegram
|
9
|
-
REQUIRED_FIELDS = %
|
10
|
-
HASH_FIELDS = %
|
9
|
+
REQUIRED_FIELDS = %w[id hash].freeze
|
10
|
+
HASH_FIELDS = %w[auth_date first_name id last_name photo_url username].freeze
|
11
11
|
SECONDS_IN_DAY = 86_400
|
12
12
|
|
13
13
|
def call(params: {})
|
@@ -19,7 +19,9 @@ module Authkeeper
|
|
19
19
|
result: {
|
20
20
|
uid: params[:id].to_s,
|
21
21
|
provider: 'telegram',
|
22
|
-
login: params[:username]
|
22
|
+
login: params[:username],
|
23
|
+
first_name: params[:first_name],
|
24
|
+
last_name: params[:last_name]
|
23
25
|
}
|
24
26
|
}
|
25
27
|
end
|
data/lib/authkeeper/container.rb
CHANGED
@@ -17,6 +17,8 @@ module Authkeeper
|
|
17
17
|
|
18
18
|
register(:jwt_encoder) { Authkeeper::JwtEncoder.new }
|
19
19
|
|
20
|
+
register('api.discord.auth_client') { Authkeeper::DiscordAuthApi::Client.new }
|
21
|
+
register('api.discord.client') { Authkeeper::DiscordApi::Client.new }
|
20
22
|
register('api.github.auth_client') { Authkeeper::GithubAuthApi::Client.new }
|
21
23
|
register('api.github.client') { Authkeeper::GithubApi::Client.new }
|
22
24
|
register('api.gitlab.auth_client') { Authkeeper::GitlabAuthApi::Client.new }
|
@@ -33,6 +35,7 @@ module Authkeeper
|
|
33
35
|
register('services.providers.google') { Authkeeper::Providers::Google.new }
|
34
36
|
register('services.providers.yandex') { Authkeeper::Providers::Yandex.new }
|
35
37
|
register('services.providers.vk') { Authkeeper::Providers::Vk.new }
|
38
|
+
register('services.providers.discord') { Authkeeper::Providers::Discord.new }
|
36
39
|
|
37
40
|
register('services.fetch_session') { Authkeeper::FetchSessionService.new }
|
38
41
|
register('services.generate_token') { Authkeeper::GenerateTokenService.new }
|
@@ -58,6 +58,17 @@ module Authkeeper
|
|
58
58
|
expires: 1.week.from_now
|
59
59
|
}.compact
|
60
60
|
end
|
61
|
+
|
62
|
+
def sign_out
|
63
|
+
access_token = cookies_token.presence || bearer_token.presence || params_token
|
64
|
+
|
65
|
+
if access_token
|
66
|
+
auth_call = Authkeeper::Container['services.fetch_session'].call(token: access_token)
|
67
|
+
auth_call[:result].destroy if auth_call[:result]
|
68
|
+
end
|
69
|
+
|
70
|
+
cookies.delete(access_token_name)
|
71
|
+
end
|
61
72
|
end
|
62
73
|
end
|
63
74
|
end
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdanov Anton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,6 +38,10 @@ files:
|
|
38
38
|
- app/controllers/authkeeper/omniauth_callbacks_controller.rb
|
39
39
|
- app/helpers/authkeeper/application_helper.rb
|
40
40
|
- app/jobs/authkeeper/application_job.rb
|
41
|
+
- app/lib/authkeeper/discord_api/client.rb
|
42
|
+
- app/lib/authkeeper/discord_api/requests/user.rb
|
43
|
+
- app/lib/authkeeper/discord_auth_api/client.rb
|
44
|
+
- app/lib/authkeeper/discord_auth_api/requests/fetch_access_token.rb
|
41
45
|
- app/lib/authkeeper/github_api/client.rb
|
42
46
|
- app/lib/authkeeper/github_api/requests/user.rb
|
43
47
|
- app/lib/authkeeper/github_api/requests/user_emails.rb
|
@@ -63,6 +67,7 @@ files:
|
|
63
67
|
- app/models/authkeeper/application_record.rb
|
64
68
|
- app/services/authkeeper/fetch_session_service.rb
|
65
69
|
- app/services/authkeeper/generate_token_service.rb
|
70
|
+
- app/services/authkeeper/providers/discord.rb
|
66
71
|
- app/services/authkeeper/providers/github.rb
|
67
72
|
- app/services/authkeeper/providers/gitlab.rb
|
68
73
|
- app/services/authkeeper/providers/google.rb
|