netsblox_api_common/
oauth.rs1use std::time::SystemTime;
2
3use derive_more::{Display, FromStr};
4use serde::{Deserialize, Serialize};
5
6#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq, Display, Hash, FromStr)]
7pub struct ClientId(String);
8
9impl ClientId {
10 pub fn new(name: String) -> Self {
11 Self(name)
12 }
13
14 pub fn as_str(&self) -> &str {
15 &self.0
16 }
17}
18
19#[derive(Deserialize, Serialize, Clone, Debug, Display)]
20pub struct CreateClientData {
21 pub name: String,
22}
23
24#[derive(Deserialize, Serialize, Clone, Debug)]
25pub struct CreatedClientData {
26 pub id: ClientId,
27 pub secret: String,
28}
29
30#[derive(Deserialize, Serialize, Clone, Debug)]
31pub struct Client {
32 pub id: ClientId,
33 pub name: String,
34}
35
36#[derive(Deserialize, Serialize, Clone, Debug, FromStr)]
37pub struct CodeId(String);
38
39impl CodeId {
40 pub fn new(name: String) -> Self {
41 Self(name)
42 }
43
44 pub fn as_str(&self) -> &str {
45 &self.0
46 }
47}
48
49#[derive(Deserialize, Serialize, Clone, Debug)]
50#[serde(rename_all = "camelCase")]
51pub struct Code {
52 pub id: CodeId,
53 pub username: String,
54 pub client_id: ClientId,
55 pub redirect_uri: String,
56 pub created_at: SystemTime,
57}
58
59#[derive(Deserialize, Serialize, Clone, Debug, Display, FromStr)]
60pub struct TokenId(String);
61
62impl TokenId {
63 pub fn new(name: String) -> Self {
64 Self(name)
65 }
66
67 pub fn as_str(&self) -> &str {
68 &self.0
69 }
70}
71
72#[derive(Deserialize, Serialize, Clone, Debug)]
73#[serde(rename_all = "camelCase")]
74pub struct Token {
75 pub id: TokenId,
76 pub client_id: ClientId,
77 pub username: String,
78 pub created_at: SystemTime,
79}
80
81#[derive(Deserialize, Serialize, Clone, Debug)]
82pub struct CreateTokenParams {
83 pub code: Option<String>,
84 pub redirect_uri: Option<String>,
85 pub grant_type: Option<String>,
86}