Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement code signatures #5

Merged
merged 4 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/code0/identities/provider/base_oauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def check_response(response)
raise Error, response.body
end

def create_identity(*)
def create_identity(response, token, token_type)
raise NotImplementedError
end

Expand Down
2 changes: 1 addition & 1 deletion sig/code0/identities.rbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Code0
module Identities
VERSION: String
class Error < StandardError end
end
end
14 changes: 14 additions & 0 deletions sig/code0/identities/identity.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Code0
module Identities
class Identity < Struct[String]
attr_reader provider: Symbol
attr_reader identitfier: String
attr_reader username: String?
attr_reader email: String?
attr_reader firstname: String?
attr_reader lastname: String?
end
end
end
18 changes: 18 additions & 0 deletions sig/code0/identities/identity_provider.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Code0
module Identities
class IdentityProvider
attr_reader providers: Hash[Symbol, Provider::BaseOauth]

def initialize: () -> void

def add_provider: (provider_type: Symbol, config: Proc | Hash[Symbol, any]) -> void

def add_named_provider: (provider_id: Symbol, provider_type: Symbol, config: Proc | Hash[Symbol, any]) -> void

def load_identity: (provider_id: Symbol, params: Hash[Symbol, any]) -> Identity

end
end
end
32 changes: 32 additions & 0 deletions sig/code0/identities/provider/base_oauth.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Code0
module Identities
module Provider
class BaseOauth
attr_reader config_loader: Proc | Hash[Symbol, any]

def initialize: (config_loader: Proc | Hash[Symbol, any]) -> void

def authorization_url: () -> String

def token_url: () -> String

def user_details_url: () -> String

def config: () -> Hash[Symbol, any]

def load_identity: (params: Hash[Symbol, any]) -> Identity

def token_payload: (code: String) -> Hash[Symbol, any]

def create_identity: (response: Net::HTTPResponse, token: String, token_type: String) -> Identity

private

def access_token: (code: String) -> Array[String]

def check_response: (response: Net::HTTPResponse) -> void

end
end
end
end
17 changes: 17 additions & 0 deletions sig/code0/identities/provider/discord.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Code0
module Identities
module Provider
class Discord < BaseOauth
def token_url: () -> "https://discord.com/api/oauth2/token"

def token_payload: (code: String) -> { code: String, grant_type: "authorization_code", redirect_uri: String, client_id: String, client_secret: String }

def user_details_url: () -> "https://discord.com/api/users/@me"

def authorization_url: () -> String

def create_identity: (response: Net::HTTPResponse) -> Identity
end
end
end
end
19 changes: 19 additions & 0 deletions sig/code0/identities/provider/github.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Code0
module Identities
module Provider
class Github < BaseOauth
def token_url: () -> "https://github.com/login/oauth/access_token"

def token_payload: (code: String) -> { code: String, redirect_uri: String, client_id: String, client_secret: String }

def user_details_url: () -> "https://api.github.com/user"

def authorization_url: () -> ::String

def private_email: (access_token: String, token_type: String) -> String

def create_identity: (response: Net::HTTPResponse, access_token: String, token_type: String) -> Identity
end
end
end
end
19 changes: 19 additions & 0 deletions sig/code0/identities/provider/gitlab.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Code0
module Identities
module Provider
class Gitlab < BaseOauth
def base_url: () -> String

def token_url: () -> ::String

def token_payload: (code: String) -> { code: String, grant_type: "authorization_code", redirect_uri: String, client_id: String, client_secret: String }

def user_details_url: () -> ::String

def authorization_url: () -> String

def create_identity: (response: Net::HTTPResponse) -> Identity
end
end
end
end
19 changes: 19 additions & 0 deletions sig/code0/identities/provider/google.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Code0
module Identities
module Provider
class Google < BaseOauth
def base_url: () -> "https://accounts.google.com"

def token_url: () -> "https://oauth2.googleapis.com/token"

def token_payload: (code: String) -> { code: String, grant_type: "authorization_code", redirect_uri: String, client_id: String, client_secret: String }

def user_details_url: () -> "https://www.googleapis.com/oauth2/v3/userinfo"

def authorization_url: () -> String

def create_identity: (response: Net::HTTPResponse) -> Identity
end
end
end
end
17 changes: 17 additions & 0 deletions sig/code0/identities/provider/microsoft.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Code0
module Identities
module Provider
class Microsoft < BaseOauth
def base_url: () -> "https://graph.microsoft.com/"

def token_url: () -> "https://login.microsoftonline.com/consumers/oauth2/v2.0/token"

def token_payload: (code: String) -> { code: String, grant_type: "authorization_code", redirect_uri: String, client_id: String, client_secret: String }

def user_details_url: () -> "https://graph.microsoft.com/oidc/userinfo"

def create_identity: (response: Net::HTTPResponse) -> Identity
end
end
end
end
5 changes: 5 additions & 0 deletions sig/code0/identities/version.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Code0
module Identities
VERSION: String
end
end