pr_01m47d15m3e54sn21z27rpy5n9/crates/contracts/src/identity.rs
Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| API and MCP server, Rust identity service, registration, site redesign | 1 | //! The identity service: accounts, credentials and sessions. |
| 2 | //! | |
| 3 | //! Each `*Args` struct is the argument of the method of the same name, | |
| 4 | //! served at `POST /rpc/<method>`. | |
| 5 | ||
| 6 | use serde::{Deserialize, Serialize}; | |
| 7 | ||
| 8 | use crate::User; | |
| 9 | ||
| 10 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 11 | #[serde(rename_all = "camelCase")] | |
| 12 | pub struct SshKey { | |
| 13 | pub id: String, | |
| 14 | pub title: String, | |
| 15 | pub fingerprint: String, | |
| 16 | /// Milliseconds since the epoch. | |
| 17 | pub created_at: u64, | |
| 18 | } | |
| 19 | ||
| 20 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 21 | #[serde(rename_all = "camelCase")] | |
| 22 | pub struct AccessToken { | |
| 23 | pub id: String, | |
| 24 | pub name: String, | |
| 25 | pub created_at: u64, | |
| 26 | } | |
| 27 | ||
| 28 | /// `sign_in`: verifies a username and password for website sign-in. | |
| 29 | /// Returns `Outcome<SignedIn>`. | |
| 30 | #[derive(Debug, Serialize, Deserialize)] | |
| 31 | pub struct SignInArgs { | |
| 32 | pub username: String, | |
| 33 | pub password: String, | |
| 34 | } | |
| 35 | ||
| 36 | #[derive(Debug, Serialize, Deserialize)] | |
| 37 | #[serde(rename_all = "camelCase")] | |
| 38 | pub struct SignedIn { | |
| 39 | pub user: User, | |
| 40 | pub session_token: String, | |
| 41 | } | |
| 42 | ||
| 43 | /// `sign_out` and `user_for_session`. | |
| 44 | #[derive(Debug, Serialize, Deserialize)] | |
| 45 | #[serde(rename_all = "camelCase")] | |
| 46 | pub struct SessionArgs { | |
| 47 | pub session_token: String, | |
| 48 | } | |
| 49 | ||
| 50 | /// `user_for_git_credentials`: the account password or an access token. | |
| 51 | #[derive(Debug, Serialize, Deserialize)] | |
| 52 | pub struct GitCredentialsArgs { | |
| 53 | pub username: String, | |
| 54 | pub secret: String, | |
| 55 | } | |
| 56 | ||
| 57 | /// `user_for_access_token`. | |
| 58 | #[derive(Debug, Serialize, Deserialize)] | |
| 59 | pub struct TokenArgs { | |
| 60 | pub token: String, | |
| 61 | } | |
| 62 | ||
| 63 | /// `user_for_ssh_key`. | |
| 64 | #[derive(Debug, Serialize, Deserialize)] | |
| 65 | pub struct FingerprintArgs { | |
| 66 | pub fingerprint: String, | |
| 67 | } | |
| 68 | ||
| 69 | /// `user_by_username`. | |
| 70 | #[derive(Debug, Serialize, Deserialize)] | |
| 71 | pub struct UsernameArgs { | |
| 72 | pub username: String, | |
| 73 | } | |
| 74 | ||
| 75 | /// `list_ssh_keys` and `list_access_tokens`. | |
| 76 | #[derive(Debug, Serialize, Deserialize)] | |
| 77 | pub struct UserArgs { | |
| 78 | pub user: User, | |
| 79 | } | |
| 80 | ||
| 81 | /// `add_ssh_key`: `public_key` is one line in OpenSSH format. | |
| 82 | /// Returns `Outcome<SshKey>`. | |
| 83 | #[derive(Debug, Serialize, Deserialize)] | |
| 84 | #[serde(rename_all = "camelCase")] | |
| 85 | pub struct AddSshKeyArgs { | |
| 86 | pub user: User, | |
| 87 | pub title: String, | |
| 88 | pub public_key: String, | |
| 89 | } | |
| 90 | ||
| 91 | /// `remove_ssh_key` and `remove_access_token`. | |
| 92 | #[derive(Debug, Serialize, Deserialize)] | |
| 93 | pub struct RemoveArgs { | |
| 94 | pub user: User, | |
| 95 | pub id: String, | |
| 96 | } | |
| 97 | ||
| 98 | /// `create_access_token`. | |
| 99 | #[derive(Debug, Serialize, Deserialize)] | |
| 100 | pub struct CreateAccessTokenArgs { | |
| 101 | pub user: User, | |
| 102 | pub name: String, | |
| 103 | } | |
| 104 | ||
| 105 | /// The plaintext token is returned once and never stored. | |
| 106 | #[derive(Debug, Serialize, Deserialize)] | |
| 107 | pub struct CreatedAccessToken { | |
| 108 | pub token: String, | |
| 109 | pub info: AccessToken, | |
| 110 | } | |
| 111 | ||
| 112 | /// `register`: creates an account and signs it in. | |
| 113 | /// Returns `Outcome<SignedIn>`. | |
| 114 | #[derive(Debug, Serialize, Deserialize)] | |
| 115 | pub struct RegisterArgs { | |
| 116 | pub username: String, | |
| 117 | pub email: String, | |
| 118 | pub password: String, | |
| 119 | } | |
| Email verification, password reset, and Git for AI scale positioning | 120 | |
| 121 | /// `verify_email`: the token from the emailed link. Returns `Outcome<User>`. | |
| 122 | #[derive(Debug, Serialize, Deserialize)] | |
| 123 | pub struct EmailTokenArgs { | |
| 124 | pub token: String, | |
| 125 | } | |
| 126 | ||
| 127 | /// `request_password_reset`. Always succeeds, so it cannot be used to find | |
| 128 | /// out which addresses have accounts. | |
| 129 | #[derive(Debug, Serialize, Deserialize)] | |
| 130 | pub struct EmailArgs { | |
| 131 | pub email: String, | |
| 132 | } | |
| 133 | ||
| 134 | /// `reset_password`: sets a new password and ends every session. | |
| 135 | /// Returns `Outcome<User>`. | |
| 136 | #[derive(Debug, Serialize, Deserialize)] | |
| 137 | pub struct ResetPasswordArgs { | |
| 138 | pub token: String, | |
| 139 | pub password: String, | |
| 140 | } |