aboutsummaryrefslogtreecommitdiff
path: root/src/client/mod.rs
blob: bb32e2c1e6ed66c1583c356a270ceeed673fd20a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
pub mod sqldb;

use thiserror::Error;
use uuid::Uuid;

use super::Identity;

#[derive(Error, Debug)]
pub enum StoreError {
    #[error("sqlx client error")]
    SqlxError(#[from] sqlx::Error),
    #[error(
        "More than one oauth provider identified, but no client_id was provided for disambiguation"
    )]
    TooManyOauthProviders,
    #[error("Oath provider not registered. First register the Oauth provider before executing")]
    OauthProviderNotRegistered,
    #[error("An unknown error occurred")]
    Unknown,
}

#[async_trait::async_trait]
pub trait Store {
    // async fn read_oauth_authorization_location(
    //     &self,
    //     provider: OauthProvider,
    //     client_id: Option<OauthClientId>,
    // ) -> Result<String, StoreError>;

    // async fn write_oauth_authorization_request(
    //     &self,
    //     identity_id: Uuid,
    //     provider: OauthProvider,
    //     raw: String,
    //     state: String,
    // ) -> Result<(), StoreError>;

    // async fn write_oauth_provider(
    //     &self,
    //     provider: OauthProvider,
    //     consent_uri: OauthConsentUri,
    //     client_id: OauthClientId,
    //     client_secret: OauthClientSecretEncrypted,
    //     redirect_uri: String,
    // ) -> Result<(), StoreError>;

    // fn read_email_challenge(&self) -> Result<T, StoreError>;
    // fn write_email_challenge(&self) -> Result<T, StoreError>;

    async fn write_email(&self, id: Uuid, email_address: &str) -> Result<(), StoreError>;
    async fn write_email_validation_request(
        &self,
        id: Uuid,
        email_address: &str,
    ) -> Result<Uuid, StoreError>;

    async fn find_identity(
        &self,
        id: Option<&Uuid>,
        email: Option<&str>,
    ) -> Result<Option<Identity>, StoreError>;
    async fn write_identity(&self, i: &Identity) -> Result<(), StoreError>;
    async fn read_identity(&self, id: &Uuid) -> Result<Identity, StoreError>;

    // fn read_sms_challenge(&self) -> Result<T, StoreError>;
    // fn write_sms_challenge(&self) -> Result<T, StoreError>;
}

// #[derive(sqlx::FromRow, Debug)]
// struct Identity {
//     #[sqlx(rename = "identity_public_id")]
//     id: Uuid,
// }

// #[derive(sqlx::FromRow, Debug)]
// struct OauthProviderRecord {
//     consent_uri: String,
//     client_id: OauthClientId,
//     client_secret_encrypted: OauthClientSecretEncrypted,
//     redirect_uri: String,
// }