code0-identities 0.0.1
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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +44 -0
- data/.tool-versions +1 -0
- data/LICENSE.txt +21 -0
- data/README.md +94 -0
- data/Rakefile +12 -0
- data/lib/code0/identities/identity.rb +7 -0
- data/lib/code0/identities/identity_provider.rb +31 -0
- data/lib/code0/identities/provider/base_oauth.rb +78 -0
- data/lib/code0/identities/provider/discord.rb +39 -0
- data/lib/code0/identities/provider/github.rb +51 -0
- data/lib/code0/identities/provider/gitlab.rb +45 -0
- data/lib/code0/identities/provider/google.rb +49 -0
- data/lib/code0/identities/provider/microsoft.rb +44 -0
- data/lib/code0/identities/version.rb +7 -0
- data/lib/code0/identities.rb +18 -0
- data/renovate.json +17 -0
- data/sig/code0/identities/identity.rbs +14 -0
- data/sig/code0/identities/identity_provider.rbs +18 -0
- data/sig/code0/identities/provider/base_oauth.rbs +32 -0
- data/sig/code0/identities/provider/discord.rbs +17 -0
- data/sig/code0/identities/provider/github.rbs +19 -0
- data/sig/code0/identities/provider/gitlab.rbs +19 -0
- data/sig/code0/identities/provider/google.rbs +19 -0
- data/sig/code0/identities/provider/microsoft.rbs +17 -0
- data/sig/code0/identities/version.rbs +5 -0
- data/sig/code0/identities.rbs +5 -0
- metadata +172 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2d2f9b0245b49ef731da01ee5592ffcb56c6211c478752fd8ec91690fe91372a
|
4
|
+
data.tar.gz: f55736bb0f4c49734b2ae95d93414ed514833131bed57bc7aeedf487a5766bef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 390747996b868eb0db1558af9da5f64f55efc232f2e6bfa54b26b03df5e0bc828fab1fd5b61db9c279c59c4ccb63f3346fb04b893089076ccb39930908421b19
|
7
|
+
data.tar.gz: 75dee3614cc0ce7e361e40105333049fd947243417b32c6ab4647e94b821c462d2a841cb9f267fdcd83f281f8bbf58704fd678c0d0ecddf305b89338f1fcdc13
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 3.0.0
|
7
|
+
NewCops: enable
|
8
|
+
|
9
|
+
Gemspec/DevelopmentDependencies:
|
10
|
+
EnforcedStyle: gemspec
|
11
|
+
|
12
|
+
Metrics/AbcSize:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/CyclomaticComplexity:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Metrics/PerceivedComplexity:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/StringLiterals:
|
25
|
+
Enabled: true
|
26
|
+
EnforcedStyle: double_quotes
|
27
|
+
|
28
|
+
Style/StringLiteralsInInterpolation:
|
29
|
+
Enabled: true
|
30
|
+
EnforcedStyle: double_quotes
|
31
|
+
|
32
|
+
Layout/LineLength:
|
33
|
+
Max: 120
|
34
|
+
|
35
|
+
RSpec/ExampleLength:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Style/Documentation:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
RSpec/MultipleMemoizedHelpers:
|
42
|
+
Enabled: false
|
43
|
+
RSpec/MultipleExpectations:
|
44
|
+
Enabled: false
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.2.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Code0::Identities [](https://github.com/code0-tech/code0-identities/actions)  
|
2
|
+
|
3
|
+
This gem can load and validate external identities
|
4
|
+
|
5
|
+
## Supported platforms
|
6
|
+
|
7
|
+
OAuth:
|
8
|
+
- Google
|
9
|
+
- Discord
|
10
|
+
- Microsoft
|
11
|
+
- Github
|
12
|
+
- Gitlab
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Install the gem and add to the application's Gemfile by executing:
|
17
|
+
|
18
|
+
$ bundle add code0-identities
|
19
|
+
|
20
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
21
|
+
|
22
|
+
$ gem install code0-identities
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
You can use predefined Providers to load an identity from for example Discord:
|
27
|
+
```ruby
|
28
|
+
|
29
|
+
require "code0/identities"
|
30
|
+
|
31
|
+
begin
|
32
|
+
|
33
|
+
identity = Code0::Identities::Provider::Discord.new(
|
34
|
+
{
|
35
|
+
redirect_uri: "http://localhost:8080/redirect",
|
36
|
+
client_id: "id",
|
37
|
+
client_secret: "xxxx"
|
38
|
+
}).load_identity({ code: "a_valid_code" })
|
39
|
+
|
40
|
+
rescue Code0::Error => e
|
41
|
+
puts "Error occurred while loading the identity", e
|
42
|
+
exit!
|
43
|
+
end
|
44
|
+
|
45
|
+
# Then you can use the details from the user
|
46
|
+
puts identity.provider # = :discord
|
47
|
+
puts identity.username
|
48
|
+
puts identity.identifier
|
49
|
+
# ...
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
Or you can use a provider with multiple configured providers:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
|
57
|
+
require "code0/identities"
|
58
|
+
|
59
|
+
identity_provider = Code0::Identities::IdentityProvider.new
|
60
|
+
|
61
|
+
identity_provider.add_provider(:gitlab, my_gitlab_configuration)
|
62
|
+
identity_provider.add_named_provider(:my_custom_gitlab_provider, :gitlab, my_custom_gitlab_provider_configuration)
|
63
|
+
|
64
|
+
# Now you can either use the custom "my_custom_gitlab_provider" provider
|
65
|
+
# or the "gitlab" provider
|
66
|
+
|
67
|
+
identity_provider.load_identity(:gitlab, params)
|
68
|
+
|
69
|
+
# or
|
70
|
+
|
71
|
+
identity_provider.load_identity(:my_custom_gitlab_provider, params)
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
We also support passing in a function as a configuration instead of a hash
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
|
79
|
+
def get_identity
|
80
|
+
provider = Code0::Identities::Provider::Discord.new(-> { fetch_configuration })
|
81
|
+
|
82
|
+
provider.load_identity(params)
|
83
|
+
end
|
84
|
+
|
85
|
+
def fetch_configuration
|
86
|
+
# Do some database action, to dynamicly load the configuration
|
87
|
+
{
|
88
|
+
redirect_uri: "http://localhost:8080/redirect",
|
89
|
+
client_id: "some dynamic value",
|
90
|
+
client_secret: "xxxx"
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Code0
|
4
|
+
module Identities
|
5
|
+
class IdentityProvider
|
6
|
+
attr_reader :providers
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@providers = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_provider(provider_type, config)
|
13
|
+
add_named_provider provider_type, provider_type, config
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_named_provider(provider_id, provider_type, config)
|
17
|
+
provider = Identities::Provider.const_get(provider_type.capitalize).new(config)
|
18
|
+
providers[provider_id] = provider
|
19
|
+
end
|
20
|
+
|
21
|
+
def load_identity(provider_id, params)
|
22
|
+
provider = providers[provider_id]
|
23
|
+
if provider.nil?
|
24
|
+
raise Error, "Provider with id '#{provider_id}' is not configured, did you forget to use add_provider"
|
25
|
+
end
|
26
|
+
|
27
|
+
provider.load_identity(params)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Code0
|
4
|
+
module Identities
|
5
|
+
module Provider
|
6
|
+
class BaseOauth
|
7
|
+
attr_reader :config_loader
|
8
|
+
|
9
|
+
def initialize(config_loader)
|
10
|
+
@config_loader = config_loader
|
11
|
+
end
|
12
|
+
|
13
|
+
def authorization_url
|
14
|
+
raise NotImplementedError
|
15
|
+
end
|
16
|
+
|
17
|
+
def token_url
|
18
|
+
raise NotImplementedError
|
19
|
+
end
|
20
|
+
|
21
|
+
def user_details_url
|
22
|
+
raise NotImplementedError
|
23
|
+
end
|
24
|
+
|
25
|
+
def token_payload(code)
|
26
|
+
raise NotImplementedError
|
27
|
+
end
|
28
|
+
|
29
|
+
def load_identity(**params)
|
30
|
+
code = params[:code]
|
31
|
+
token, token_type = access_token code
|
32
|
+
|
33
|
+
response = HTTParty.get(user_details_url,
|
34
|
+
headers: {
|
35
|
+
Authorization: "#{token_type} #{token}",
|
36
|
+
"Accept" => "application/json"
|
37
|
+
})
|
38
|
+
|
39
|
+
check_response response
|
40
|
+
|
41
|
+
create_identity response, token, token_type
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def access_token(code)
|
47
|
+
response = HTTParty.post(token_url,
|
48
|
+
body: URI.encode_www_form(token_payload(code)), headers: {
|
49
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
50
|
+
"Accept" => "application/json"
|
51
|
+
})
|
52
|
+
|
53
|
+
check_response response
|
54
|
+
|
55
|
+
parsed = response.parsed_response
|
56
|
+
|
57
|
+
[parsed["access_token"], parsed["token_type"]]
|
58
|
+
end
|
59
|
+
|
60
|
+
def check_response(response)
|
61
|
+
return if response.code == 200
|
62
|
+
|
63
|
+
raise Error, response.body
|
64
|
+
end
|
65
|
+
|
66
|
+
def create_identity(response, token, token_type)
|
67
|
+
raise NotImplementedError
|
68
|
+
end
|
69
|
+
|
70
|
+
def config
|
71
|
+
return config_loader.call if config_loader.is_a?(Proc)
|
72
|
+
|
73
|
+
config_loader
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Code0
|
4
|
+
module Identities
|
5
|
+
module Provider
|
6
|
+
class Discord < BaseOauth
|
7
|
+
def token_url
|
8
|
+
"https://discord.com/api/oauth2/token"
|
9
|
+
end
|
10
|
+
|
11
|
+
def token_payload(code)
|
12
|
+
{ code: code,
|
13
|
+
grant_type: "authorization_code",
|
14
|
+
redirect_uri: config[:redirect_uri],
|
15
|
+
client_id: config[:client_id],
|
16
|
+
client_secret: config[:client_secret] }
|
17
|
+
end
|
18
|
+
|
19
|
+
def user_details_url
|
20
|
+
"https://discord.com/api/users/@me"
|
21
|
+
end
|
22
|
+
|
23
|
+
def authorization_url
|
24
|
+
"https://discord.com/oauth2/authorize?client_id=#{config[:client_id]}&response_type=code&redirect_uri=#{URI.encode_uri_component(config[:redirect_uri])}&scope=identify+openid+email"
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_identity(response, *)
|
28
|
+
body = response.parsed_response
|
29
|
+
|
30
|
+
identifier = body["id"]
|
31
|
+
username = body["username"]
|
32
|
+
email = body["email"]
|
33
|
+
|
34
|
+
Identity.new(:discord, identifier, username, email, nil, nil)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Code0
|
4
|
+
module Identities
|
5
|
+
module Provider
|
6
|
+
class Github < BaseOauth
|
7
|
+
def token_url
|
8
|
+
"https://github.com/login/oauth/access_token"
|
9
|
+
end
|
10
|
+
|
11
|
+
def token_payload(code)
|
12
|
+
{ code: code,
|
13
|
+
redirect_uri: config[:redirect_uri],
|
14
|
+
client_id: config[:client_id],
|
15
|
+
client_secret: config[:client_secret] }
|
16
|
+
end
|
17
|
+
|
18
|
+
def user_details_url
|
19
|
+
"https://api.github.com/user"
|
20
|
+
end
|
21
|
+
|
22
|
+
def authorization_url
|
23
|
+
"https://github.com/login/oauth/authorize?client_id=#{config[:client_id]}&redirect_uri=#{URI.encode_uri_component(config[:redirect_uri])}&scope=read:user+user:email"
|
24
|
+
end
|
25
|
+
|
26
|
+
def private_email(access_token, token_type)
|
27
|
+
response = HTTParty.get("#{user_details_url}/emails",
|
28
|
+
headers: {
|
29
|
+
Authorization: "#{token_type} #{access_token}",
|
30
|
+
"Accept" => "application/json"
|
31
|
+
})
|
32
|
+
body = response.parsed_response
|
33
|
+
|
34
|
+
body.find { |email_object| email_object["primary"] }["email"]
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_identity(response, access_token, token_type)
|
38
|
+
body = response.parsed_response
|
39
|
+
|
40
|
+
identifier = body["id"]
|
41
|
+
username = body["login"]
|
42
|
+
email = body["email"]
|
43
|
+
|
44
|
+
email = private_email(access_token, token_type) if email.nil?
|
45
|
+
|
46
|
+
Identity.new(:github, identifier, username, email, nil, nil)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Code0
|
4
|
+
module Identities
|
5
|
+
module Provider
|
6
|
+
class Gitlab < BaseOauth
|
7
|
+
def base_url
|
8
|
+
config[:base_url]
|
9
|
+
end
|
10
|
+
|
11
|
+
def token_url
|
12
|
+
"#{base_url}/oauth/token"
|
13
|
+
end
|
14
|
+
|
15
|
+
def token_payload(code)
|
16
|
+
{ code: code,
|
17
|
+
grant_type: "authorization_code",
|
18
|
+
redirect_uri: config[:redirect_uri],
|
19
|
+
client_id: config[:client_id],
|
20
|
+
client_secret: config[:client_secret] }
|
21
|
+
end
|
22
|
+
|
23
|
+
def user_details_url
|
24
|
+
"#{base_url}/api/v4/user"
|
25
|
+
end
|
26
|
+
|
27
|
+
def authorization_url
|
28
|
+
# rubocop:disable Layout/LineLength
|
29
|
+
base_url + "/oauth/authorize?client_id=#{config[:client_id]}&response_type=code&redirect_uri=#{URI.encode_uri_component(config[:redirect_uri])}&scope=read_user"
|
30
|
+
# rubocop:enable Layout/LineLength
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_identity(response, *)
|
34
|
+
body = response.parsed_response
|
35
|
+
|
36
|
+
identifier = body["id"]
|
37
|
+
username = body["username"]
|
38
|
+
email = body["email"]
|
39
|
+
|
40
|
+
Identity.new(config_loader.call[:provider_name], identifier, username, email, nil, nil)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Code0
|
4
|
+
module Identities
|
5
|
+
module Provider
|
6
|
+
class Google < BaseOauth
|
7
|
+
def base_url
|
8
|
+
"https://accounts.google.com"
|
9
|
+
end
|
10
|
+
|
11
|
+
def token_url
|
12
|
+
"https://oauth2.googleapis.com/token"
|
13
|
+
end
|
14
|
+
|
15
|
+
def token_payload(code)
|
16
|
+
{
|
17
|
+
code: code,
|
18
|
+
grant_type: "authorization_code",
|
19
|
+
redirect_uri: config[:redirect_uri],
|
20
|
+
client_id: config[:client_id],
|
21
|
+
client_secret: config[:client_secret]
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def user_details_url
|
26
|
+
"https://www.googleapis.com/oauth2/v3/userinfo"
|
27
|
+
end
|
28
|
+
|
29
|
+
def authorization_url
|
30
|
+
# rubocop:disable Layout/LineLength
|
31
|
+
base_url + "/o/oauth2/v2/auth?client_id=#{config[:client_id]}&response_type=code&redirect_uri=#{URI.encode_www_form_component(config[:redirect_uri])}&scope=openid%20email%20profile"
|
32
|
+
# rubocop:enable Layout/LineLength
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_identity(response, *)
|
36
|
+
body = response.parsed_response
|
37
|
+
|
38
|
+
identifier = body["sub"]
|
39
|
+
username = body["name"]
|
40
|
+
email = body["email"]
|
41
|
+
firstname = body["given_name"]
|
42
|
+
lastname = body["family_name"]
|
43
|
+
|
44
|
+
Identity.new(:google, identifier, username, email, firstname, lastname)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Code0
|
4
|
+
module Identities
|
5
|
+
module Provider
|
6
|
+
class Microsoft < BaseOauth
|
7
|
+
def base_url
|
8
|
+
"https://graph.microsoft.com/"
|
9
|
+
end
|
10
|
+
|
11
|
+
def token_url
|
12
|
+
"https://login.microsoftonline.com/consumers/oauth2/v2.0/token"
|
13
|
+
end
|
14
|
+
|
15
|
+
def token_payload(code)
|
16
|
+
{ code: code,
|
17
|
+
grant_type: "authorization_code",
|
18
|
+
redirect_uri: config[:redirect_uri],
|
19
|
+
client_id: config[:client_id],
|
20
|
+
client_secret: config[:client_secret] }
|
21
|
+
end
|
22
|
+
|
23
|
+
def user_details_url
|
24
|
+
"https://graph.microsoft.com/oidc/userinfo"
|
25
|
+
end
|
26
|
+
|
27
|
+
def authorization_url
|
28
|
+
"https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?client_id=#{config[:client_id]}&response_type=code&redirect_uri=#{config[:redirect_uri]}&response_mode=query&scope=email%20profile%20openid"
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_identity(response, *)
|
32
|
+
body = response.parsed_response
|
33
|
+
|
34
|
+
identifier = body["sub"]
|
35
|
+
firstname = body["givenname"]
|
36
|
+
lastname = body["familyname"]
|
37
|
+
email = body["email"]
|
38
|
+
|
39
|
+
Identity.new(:microsoft, identifier, nil, email, firstname, lastname)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "httparty"
|
4
|
+
|
5
|
+
require_relative "identities/version"
|
6
|
+
require_relative "identities/identity_provider"
|
7
|
+
require_relative "identities/identity"
|
8
|
+
require_relative "identities/provider/base_oauth"
|
9
|
+
require_relative "identities/provider/microsoft"
|
10
|
+
require_relative "identities/provider/google"
|
11
|
+
require_relative "identities/provider/discord"
|
12
|
+
require_relative "identities/provider/github"
|
13
|
+
|
14
|
+
module Code0
|
15
|
+
module Identities
|
16
|
+
class Error < StandardError; end
|
17
|
+
end
|
18
|
+
end
|
data/renovate.json
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
3
|
+
"extends": [
|
4
|
+
"config:recommended",
|
5
|
+
":label(dependencies)"
|
6
|
+
],
|
7
|
+
"assignees": [
|
8
|
+
"Taucher2003",
|
9
|
+
"Knerio"
|
10
|
+
],
|
11
|
+
"packageRules": [
|
12
|
+
{
|
13
|
+
"matchDepNames": ["ruby"],
|
14
|
+
"dependencyDashboardApproval": true
|
15
|
+
}
|
16
|
+
]
|
17
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Code0
|
4
|
+
module Identities
|
5
|
+
class Identity < Struct[String]
|
6
|
+
attr_reader provider: Symbol
|
7
|
+
attr_reader identitfier: String
|
8
|
+
attr_reader username: String?
|
9
|
+
attr_reader email: String?
|
10
|
+
attr_reader firstname: String?
|
11
|
+
attr_reader lastname: String?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Code0
|
4
|
+
module Identities
|
5
|
+
class IdentityProvider
|
6
|
+
attr_reader providers: Hash[Symbol, Provider::BaseOauth]
|
7
|
+
|
8
|
+
def initialize: () -> void
|
9
|
+
|
10
|
+
def add_provider: (provider_type: Symbol, config: Proc | Hash[Symbol, any]) -> void
|
11
|
+
|
12
|
+
def add_named_provider: (provider_id: Symbol, provider_type: Symbol, config: Proc | Hash[Symbol, any]) -> void
|
13
|
+
|
14
|
+
def load_identity: (provider_id: Symbol, params: Hash[Symbol, any]) -> Identity
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Code0
|
2
|
+
module Identities
|
3
|
+
module Provider
|
4
|
+
class BaseOauth
|
5
|
+
attr_reader config_loader: Proc | Hash[Symbol, any]
|
6
|
+
|
7
|
+
def initialize: (config_loader: Proc | Hash[Symbol, any]) -> void
|
8
|
+
|
9
|
+
def authorization_url: () -> String
|
10
|
+
|
11
|
+
def token_url: () -> String
|
12
|
+
|
13
|
+
def user_details_url: () -> String
|
14
|
+
|
15
|
+
def config: () -> Hash[Symbol, any]
|
16
|
+
|
17
|
+
def load_identity: (params: Hash[Symbol, any]) -> Identity
|
18
|
+
|
19
|
+
def token_payload: (code: String) -> Hash[Symbol, any]
|
20
|
+
|
21
|
+
def create_identity: (response: Net::HTTPResponse, token: String, token_type: String) -> Identity
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def access_token: (code: String) -> Array[String]
|
26
|
+
|
27
|
+
def check_response: (response: Net::HTTPResponse) -> void
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Code0
|
2
|
+
module Identities
|
3
|
+
module Provider
|
4
|
+
class Discord < BaseOauth
|
5
|
+
def token_url: () -> "https://discord.com/api/oauth2/token"
|
6
|
+
|
7
|
+
def token_payload: (code: String) -> { code: String, grant_type: "authorization_code", redirect_uri: String, client_id: String, client_secret: String }
|
8
|
+
|
9
|
+
def user_details_url: () -> "https://discord.com/api/users/@me"
|
10
|
+
|
11
|
+
def authorization_url: () -> String
|
12
|
+
|
13
|
+
def create_identity: (response: Net::HTTPResponse) -> Identity
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Code0
|
2
|
+
module Identities
|
3
|
+
module Provider
|
4
|
+
class Github < BaseOauth
|
5
|
+
def token_url: () -> "https://github.com/login/oauth/access_token"
|
6
|
+
|
7
|
+
def token_payload: (code: String) -> { code: String, redirect_uri: String, client_id: String, client_secret: String }
|
8
|
+
|
9
|
+
def user_details_url: () -> "https://api.github.com/user"
|
10
|
+
|
11
|
+
def authorization_url: () -> ::String
|
12
|
+
|
13
|
+
def private_email: (access_token: String, token_type: String) -> String
|
14
|
+
|
15
|
+
def create_identity: (response: Net::HTTPResponse, access_token: String, token_type: String) -> Identity
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Code0
|
2
|
+
module Identities
|
3
|
+
module Provider
|
4
|
+
class Gitlab < BaseOauth
|
5
|
+
def base_url: () -> String
|
6
|
+
|
7
|
+
def token_url: () -> ::String
|
8
|
+
|
9
|
+
def token_payload: (code: String) -> { code: String, grant_type: "authorization_code", redirect_uri: String, client_id: String, client_secret: String }
|
10
|
+
|
11
|
+
def user_details_url: () -> ::String
|
12
|
+
|
13
|
+
def authorization_url: () -> String
|
14
|
+
|
15
|
+
def create_identity: (response: Net::HTTPResponse) -> Identity
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Code0
|
2
|
+
module Identities
|
3
|
+
module Provider
|
4
|
+
class Google < BaseOauth
|
5
|
+
def base_url: () -> "https://accounts.google.com"
|
6
|
+
|
7
|
+
def token_url: () -> "https://oauth2.googleapis.com/token"
|
8
|
+
|
9
|
+
def token_payload: (code: String) -> { code: String, grant_type: "authorization_code", redirect_uri: String, client_id: String, client_secret: String }
|
10
|
+
|
11
|
+
def user_details_url: () -> "https://www.googleapis.com/oauth2/v3/userinfo"
|
12
|
+
|
13
|
+
def authorization_url: () -> String
|
14
|
+
|
15
|
+
def create_identity: (response: Net::HTTPResponse) -> Identity
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Code0
|
2
|
+
module Identities
|
3
|
+
module Provider
|
4
|
+
class Microsoft < BaseOauth
|
5
|
+
def base_url: () -> "https://graph.microsoft.com/"
|
6
|
+
|
7
|
+
def token_url: () -> "https://login.microsoftonline.com/consumers/oauth2/v2.0/token"
|
8
|
+
|
9
|
+
def token_payload: (code: String) -> { code: String, grant_type: "authorization_code", redirect_uri: String, client_id: String, client_secret: String }
|
10
|
+
|
11
|
+
def user_details_url: () -> "https://graph.microsoft.com/oidc/userinfo"
|
12
|
+
|
13
|
+
def create_identity: (response: Net::HTTPResponse) -> Identity
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: code0-identities
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dario Pranjic
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-08-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.22'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.22'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: webmock
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.23.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.23.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.21'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.21'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.29'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.29'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- dpranjic@code0.tech
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".rspec"
|
119
|
+
- ".rubocop.yml"
|
120
|
+
- ".tool-versions"
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- lib/code0/identities.rb
|
125
|
+
- lib/code0/identities/identity.rb
|
126
|
+
- lib/code0/identities/identity_provider.rb
|
127
|
+
- lib/code0/identities/provider/base_oauth.rb
|
128
|
+
- lib/code0/identities/provider/discord.rb
|
129
|
+
- lib/code0/identities/provider/github.rb
|
130
|
+
- lib/code0/identities/provider/gitlab.rb
|
131
|
+
- lib/code0/identities/provider/google.rb
|
132
|
+
- lib/code0/identities/provider/microsoft.rb
|
133
|
+
- lib/code0/identities/version.rb
|
134
|
+
- renovate.json
|
135
|
+
- sig/code0/identities.rbs
|
136
|
+
- sig/code0/identities/identity.rbs
|
137
|
+
- sig/code0/identities/identity_provider.rbs
|
138
|
+
- sig/code0/identities/provider/base_oauth.rbs
|
139
|
+
- sig/code0/identities/provider/discord.rbs
|
140
|
+
- sig/code0/identities/provider/github.rbs
|
141
|
+
- sig/code0/identities/provider/gitlab.rbs
|
142
|
+
- sig/code0/identities/provider/google.rbs
|
143
|
+
- sig/code0/identities/provider/microsoft.rbs
|
144
|
+
- sig/code0/identities/version.rbs
|
145
|
+
homepage: https://github.com/code0-tech/code0-identities
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata:
|
149
|
+
homepage_uri: https://github.com/code0-tech/code0-identities
|
150
|
+
source_code_uri: https://github.com/code0-tech/code0-identities
|
151
|
+
changelog_uri: https://github.com/code0-tech/code0-identities/releases
|
152
|
+
rubygems_mfa_required: 'true'
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: 3.0.0
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubygems_version: 3.4.10
|
169
|
+
signing_key:
|
170
|
+
specification_version: 4
|
171
|
+
summary: Library to manage external identities
|
172
|
+
test_files: []
|