Skip to content

Commit 559f177

Browse files
committed
implement code signatures
1 parent 37dc109 commit 559f177

File tree

11 files changed

+151
-2
lines changed

11 files changed

+151
-2
lines changed

lib/code0/identities/provider/base_oauth.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def check_response(response)
6363
raise Error, response.body
6464
end
6565

66-
def create_identity(*)
66+
def create_identity(response, token, token_type)
6767
raise NotImplementedError
6868
end
6969

sig/code0/identities.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Code0
22
module Identities
3-
VERSION: String
3+
class Error < StandardError end
44
end
55
end

sig/code0/identities/identity.rbs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
module Code0
4+
module Identities
5+
class IdentityProvider
6+
attr_reader providers: Array[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
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 create_identity: (response: Net::HTTPResponse, token: String, token_type: String) -> Identity
18+
end
19+
end
20+
end
21+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: (untyped code) -> { 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
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)