From 559f17774e5d731847ba1f2461c6fcebdca6d8e3 Mon Sep 17 00:00:00 2001 From: Dario P Date: Sun, 25 Aug 2024 18:12:18 +0200 Subject: [PATCH] implement code signatures --- lib/code0/identities/provider/base_oauth.rb | 2 +- sig/code0/identities.rbs | 2 +- sig/code0/identities/identity.rbs | 14 +++++++++++++ sig/code0/identities/identity_provider.rbs | 18 +++++++++++++++++ sig/code0/identities/provider/base_oauth.rbs | 21 ++++++++++++++++++++ sig/code0/identities/provider/discord.rbs | 17 ++++++++++++++++ sig/code0/identities/provider/github.rbs | 19 ++++++++++++++++++ sig/code0/identities/provider/gitlab.rbs | 19 ++++++++++++++++++ sig/code0/identities/provider/google.rbs | 19 ++++++++++++++++++ sig/code0/identities/provider/microsoft.rbs | 17 ++++++++++++++++ sig/code0/identities/version.rbs | 5 +++++ 11 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 sig/code0/identities/identity.rbs create mode 100644 sig/code0/identities/identity_provider.rbs create mode 100644 sig/code0/identities/provider/base_oauth.rbs create mode 100644 sig/code0/identities/provider/discord.rbs create mode 100644 sig/code0/identities/provider/github.rbs create mode 100644 sig/code0/identities/provider/gitlab.rbs create mode 100644 sig/code0/identities/provider/google.rbs create mode 100644 sig/code0/identities/provider/microsoft.rbs create mode 100644 sig/code0/identities/version.rbs diff --git a/lib/code0/identities/provider/base_oauth.rb b/lib/code0/identities/provider/base_oauth.rb index b02eb16..995e132 100644 --- a/lib/code0/identities/provider/base_oauth.rb +++ b/lib/code0/identities/provider/base_oauth.rb @@ -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 diff --git a/sig/code0/identities.rbs b/sig/code0/identities.rbs index f195ac5..5f88fd5 100644 --- a/sig/code0/identities.rbs +++ b/sig/code0/identities.rbs @@ -1,5 +1,5 @@ module Code0 module Identities - VERSION: String + class Error < StandardError end end end diff --git a/sig/code0/identities/identity.rbs b/sig/code0/identities/identity.rbs new file mode 100644 index 0000000..9557429 --- /dev/null +++ b/sig/code0/identities/identity.rbs @@ -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 diff --git a/sig/code0/identities/identity_provider.rbs b/sig/code0/identities/identity_provider.rbs new file mode 100644 index 0000000..68c725a --- /dev/null +++ b/sig/code0/identities/identity_provider.rbs @@ -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 diff --git a/sig/code0/identities/provider/base_oauth.rbs b/sig/code0/identities/provider/base_oauth.rbs new file mode 100644 index 0000000..552eed9 --- /dev/null +++ b/sig/code0/identities/provider/base_oauth.rbs @@ -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 diff --git a/sig/code0/identities/provider/discord.rbs b/sig/code0/identities/provider/discord.rbs new file mode 100644 index 0000000..08a0218 --- /dev/null +++ b/sig/code0/identities/provider/discord.rbs @@ -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 diff --git a/sig/code0/identities/provider/github.rbs b/sig/code0/identities/provider/github.rbs new file mode 100644 index 0000000..d4ef086 --- /dev/null +++ b/sig/code0/identities/provider/github.rbs @@ -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 diff --git a/sig/code0/identities/provider/gitlab.rbs b/sig/code0/identities/provider/gitlab.rbs new file mode 100644 index 0000000..f8ad700 --- /dev/null +++ b/sig/code0/identities/provider/gitlab.rbs @@ -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 diff --git a/sig/code0/identities/provider/google.rbs b/sig/code0/identities/provider/google.rbs new file mode 100644 index 0000000..4d97288 --- /dev/null +++ b/sig/code0/identities/provider/google.rbs @@ -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 diff --git a/sig/code0/identities/provider/microsoft.rbs b/sig/code0/identities/provider/microsoft.rbs new file mode 100644 index 0000000..39786d0 --- /dev/null +++ b/sig/code0/identities/provider/microsoft.rbs @@ -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 diff --git a/sig/code0/identities/version.rbs b/sig/code0/identities/version.rbs new file mode 100644 index 0000000..76b9b93 --- /dev/null +++ b/sig/code0/identities/version.rbs @@ -0,0 +1,5 @@ +module Code0 + module Identities + VERSION: String + end +end \ No newline at end of file