Skip to content

Commit

Permalink
implement code signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
Knerio committed Aug 25, 2024
1 parent 37dc109 commit 559f177
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 2 deletions.
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: Array[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
21 changes: 21 additions & 0 deletions sig/code0/identities/provider/base_oauth.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 create_identity: (response: Net::HTTPResponse, token: String, token_type: String) -> Identity
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: (untyped code) -> { 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

0 comments on commit 559f177

Please sign in to comment.