clerk_rs/models/create_user_request.rs
1/*
2 * Clerk Backend API
3 *
4 * The Clerk REST Backend API, meant to be accessed by backend servers. Please see https://clerk.com/docs for more information.
5 *
6 * The version of the OpenAPI document: v1
7 * Contact: support@clerk.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
12pub struct CreateUserRequest {
13 /// The ID of the user as used in your external systems or your previous authentication solution. Must be unique across your instance.
14 #[serde(
15 rename = "external_id",
16 default,
17 with = "::serde_with::rust::double_option",
18 skip_serializing_if = "Option::is_none"
19 )]
20 pub external_id: Option<Option<String>>,
21 /// The first name to assign to the user
22 #[serde(
23 rename = "first_name",
24 default,
25 with = "::serde_with::rust::double_option",
26 skip_serializing_if = "Option::is_none"
27 )]
28 pub first_name: Option<Option<String>>,
29 /// The last name to assign to the user
30 #[serde(
31 rename = "last_name",
32 default,
33 with = "::serde_with::rust::double_option",
34 skip_serializing_if = "Option::is_none"
35 )]
36 pub last_name: Option<Option<String>>,
37 /// Email addresses to add to the user. Must be unique across your instance. The first email address will be set as the user's primary email address.
38 #[serde(rename = "email_address", skip_serializing_if = "Option::is_none")]
39 pub email_address: Option<Vec<String>>,
40 /// Phone numbers to add to the user. Must be unique across your instance. The first phone number will be set as the user's primary phone number.
41 #[serde(rename = "phone_number", skip_serializing_if = "Option::is_none")]
42 pub phone_number: Option<Vec<String>>,
43 /// Web3 wallets to add to the user. Must be unique across your instance. The first wallet will be set as the user's primary wallet.
44 #[serde(rename = "web3_wallet", skip_serializing_if = "Option::is_none")]
45 pub web3_wallet: Option<Vec<String>>,
46 /// The username to give to the user. It must be unique across your instance.
47 #[serde(
48 rename = "username",
49 default,
50 with = "::serde_with::rust::double_option",
51 skip_serializing_if = "Option::is_none"
52 )]
53 pub username: Option<Option<String>>,
54 /// The plaintext password to give the user. Must be at least 8 characters long, and can not be in any list of hacked passwords.
55 #[serde(
56 rename = "password",
57 default,
58 with = "::serde_with::rust::double_option",
59 skip_serializing_if = "Option::is_none"
60 )]
61 pub password: Option<Option<String>>,
62 /// In case you already have the password digests and not the passwords, you can use them for the newly created user via this property. The digests should be generated with one of the supported algorithms. The hashing algorithm can be specified using the `password_hasher` property.
63 #[serde(rename = "password_digest", skip_serializing_if = "Option::is_none")]
64 pub password_digest: Option<String>,
65 /// The hashing algorithm that was used to generate the password digest. The algorithms we support at the moment are [bcrypt](https://en.wikipedia.org/wiki/Bcrypt), [bcrypt_sha256_django](https://docs.djangoproject.com/en/4.0/topics/auth/passwords/), [md5](https://en.wikipedia.org/wiki/MD5), pbkdf2_sha256, [pbkdf2_sha256_django](https://docs.djangoproject.com/en/4.0/topics/auth/passwords/), [phpass](https://www.openwall.com/phpass/), [scrypt_firebase](https://firebaseopensource.com/projects/firebase/scrypt/), [sha256](https://en.wikipedia.org/wiki/SHA-2) and the [argon2](https://argon2.online/) variants argon2i and argon2id. If you need support for any particular hashing algorithm, [please let us know](https://clerk.com/support). Note: for password hashers considered insecure (at this moment MD5 and SHA256), the corresponding user password hashes will be transparently migrated to Bcrypt (a secure hasher) upon the user's first successful password sign in. Insecure schemes are marked with `(insecure)` in the list below. Each of the supported hashers expects the incoming digest to be in a particular format. Specifically: **bcrypt:** The digest should be of the following form: `$<algorithm version>$<cost>$<salt & hash>` **bcrypt_sha256_django:** This is the Django-specific variant of Bcrypt, using SHA256 hashing function. The format should be as follows (as exported from Django): `bcrypt_sha256$$<algorithm version>$<cost>$<salt & hash>` **md5** (insecure): The digest should follow the regular form e.g.: `5f4dcc3b5aa765d61d8327deb882cf99` **pbkdf2_sha256:** This is the PBKDF2 algorithm using the SHA256 hashing function. The format should be as follows: `pbkdf2_sha256$<iterations>$<salt>$<hash>` Note: Both the salt and the hash are expected to be base64-encoded. **pbkdf2_sha256_django:** This is the Django-specific variant of PBKDF2 and the digest should have the following format (as exported from Django): `pbkdf2_sha256$<iterations>$<salt>$<hash>` Note: The salt is expected to be un-encoded, the hash is expected base64-encoded. **pbkdf2_sha1:** This is similar to pkbdf2_sha256_django, but with two differences: 1. uses sha1 instead of sha256 2. accepts the hash as a hex-encoded string The format is the following: `pbkdf2_sha1$<iterations>$<salt>$<hash-as-hex-string>` **phpass:** Portable public domain password hashing framework for use in PHP applications. Digests hashed with phpass have the following sections: The format is the following: `$P$<rounds><salt><encoded-checksum>` - $P$ is the prefix used to identify phpass hashes. - rounds is a single character encoding a 6-bit integer representing the number of rounds used. - salt is eight characters drawn from [./0-9A-Za-z], providing a 48-bit salt. - checksum is 22 characters drawn from the same set, encoding the 128-bit checksum with MD5. **scrypt_firebase:** The Firebase-specific variant of scrypt. The value is expected to have 6 segments separated by the $ character and include the following information: _hash:_ The actual Base64 hash. This can be retrieved when exporting the user from Firebase. _salt:_ The salt used to generate the above hash. Again, this is given when exporting the user. _signer key:_ The base64 encoded signer key. _salt separator:_ The base64 encoded salt separator. _rounds:_ The number of rounds the algorithm needs to run. _memory cost:_ The cost of the algorithm run The first 2 (hash and salt) are per user and can be retrieved when exporting the user from Firebase. The other 4 values (signer key, salt separator, rounds and memory cost) are project-wide settings and can be retrieved from the project's password hash parameters. Once you have all these, you can combine it in the following format and send this as the digest in order for Clerk to accept it: `<hash>$<salt>$<signer key>$<salt separator>$<rounds>$<memory cost>` **argon2i:** Algorithms in the argon2 family generate digests that encode the following information: _version (v):_ The argon version, version 19 is assumed _memory (m):_ The memory used by the algorithm (in kibibytes) _iterations (t):_ The number of iterations to perform _parallelism (p):_ The number of threads to use Parts are demarcated by the `$` character, with the first part identifying the algorithm variant. The middle part is a comma-separated list of the encoding options (memory, iterations, parallelism). The final part is the actual digest. `$argon2i$v=19$m=4096,t=3,p=1$4t6CL3P7YiHBtwESXawI8Hm20zJj4cs7/4/G3c187e0$m7RQFczcKr5bIR0IIxbpO2P0tyrLjf3eUW3M3QSwnLc` **argon2id:** See the previous algorithm for an explanation of the formatting. For the argon2id case, the value of the algorithm in the first part of the digest is `argon2id`: `$argon2id$v=19$m=64,t=4,p=8$Z2liZXJyaXNo$iGXEpMBTDYQ8G/71tF0qGjxRHEmR3gpGULcE93zUJVU` **sha256** (insecure): The digest should be a 64-length hex string, e.g.: `9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08`
66 #[serde(rename = "password_hasher", skip_serializing_if = "Option::is_none")]
67 pub password_hasher: Option<PasswordHasher>,
68 /// When set to `true` all password checks are skipped. It is recommended to use this method only when migrating plaintext passwords to Clerk. Upon migration the user base should be prompted to pick stronger password.
69 #[serde(rename = "skip_password_checks", skip_serializing_if = "Option::is_none")]
70 pub skip_password_checks: Option<bool>,
71 /// When set to `true`, `password` is not required anymore when creating the user and can be omitted. This is useful when you are trying to create a user that doesn't have a password, in an instance that is using passwords. Please note that you cannot use this flag if password is the only way for a user to sign into your instance.
72 #[serde(rename = "skip_password_requirement", skip_serializing_if = "Option::is_none")]
73 pub skip_password_requirement: Option<bool>,
74 /// In case TOTP is configured on the instance, you can provide the secret to enable it on the newly created user without the need to reset it. Please note that currently the supported options are: * Period: 30 seconds * Code length: 6 digits * Algorithm: SHA1
75 #[serde(rename = "totp_secret", skip_serializing_if = "Option::is_none")]
76 pub totp_secret: Option<String>,
77 /// If Backup Codes are configured on the instance, you can provide them to enable it on the newly created user without the need to reset them. You must provide the backup codes in plain format or the corresponding bcrypt digest.
78 #[serde(rename = "backup_codes", skip_serializing_if = "Option::is_none")]
79 pub backup_codes: Option<Vec<String>>,
80 /// Metadata saved on the user, that is visible to both your Frontend and Backend APIs
81 #[serde(rename = "public_metadata", skip_serializing_if = "Option::is_none")]
82 pub public_metadata: Option<serde_json::Value>,
83 /// Metadata saved on the user, that is only visible to your Backend API
84 #[serde(rename = "private_metadata", skip_serializing_if = "Option::is_none")]
85 pub private_metadata: Option<serde_json::Value>,
86 /// Metadata saved on the user, that can be updated from both the Frontend and Backend APIs. Note: Since this data can be modified from the frontend, it is not guaranteed to be safe.
87 #[serde(rename = "unsafe_metadata", skip_serializing_if = "Option::is_none")]
88 pub unsafe_metadata: Option<serde_json::Value>,
89 /// A custom date/time denoting _when_ the user signed up to the application, specified in RFC3339 format (e.g. `2012-10-20T07:15:20.902Z`).
90 #[serde(rename = "created_at", skip_serializing_if = "Option::is_none")]
91 pub created_at: Option<String>,
92}
93
94impl CreateUserRequest {
95 pub fn new() -> CreateUserRequest {
96 CreateUserRequest {
97 external_id: None,
98 first_name: None,
99 last_name: None,
100 email_address: None,
101 phone_number: None,
102 web3_wallet: None,
103 username: None,
104 password: None,
105 password_digest: None,
106 password_hasher: None,
107 skip_password_checks: None,
108 skip_password_requirement: None,
109 totp_secret: None,
110 backup_codes: None,
111 public_metadata: None,
112 private_metadata: None,
113 unsafe_metadata: None,
114 created_at: None,
115 }
116 }
117}
118
119/// The hashing algorithm that was used to generate the password digest. The algorithms we support at the moment are [bcrypt](https://en.wikipedia.org/wiki/Bcrypt), [bcrypt_sha256_django](https://docs.djangoproject.com/en/4.0/topics/auth/passwords/), [md5](https://en.wikipedia.org/wiki/MD5), pbkdf2_sha256, [pbkdf2_sha256_django](https://docs.djangoproject.com/en/4.0/topics/auth/passwords/), [phpass](https://www.openwall.com/phpass/), [scrypt_firebase](https://firebaseopensource.com/projects/firebase/scrypt/), [sha256](https://en.wikipedia.org/wiki/SHA-2) and the [argon2](https://argon2.online/) variants argon2i and argon2id. If you need support for any particular hashing algorithm, [please let us know](https://clerk.com/support). Note: for password hashers considered insecure (at this moment MD5 and SHA256), the corresponding user password hashes will be transparently migrated to Bcrypt (a secure hasher) upon the user's first successful password sign in. Insecure schemes are marked with `(insecure)` in the list below. Each of the supported hashers expects the incoming digest to be in a particular format. Specifically: **bcrypt:** The digest should be of the following form: `$<algorithm version>$<cost>$<salt & hash>` **bcrypt_sha256_django:** This is the Django-specific variant of Bcrypt, using SHA256 hashing function. The format should be as follows (as exported from Django): `bcrypt_sha256$$<algorithm version>$<cost>$<salt & hash>` **md5** (insecure): The digest should follow the regular form e.g.: `5f4dcc3b5aa765d61d8327deb882cf99` **pbkdf2_sha256:** This is the PBKDF2 algorithm using the SHA256 hashing function. The format should be as follows: `pbkdf2_sha256$<iterations>$<salt>$<hash>` Note: Both the salt and the hash are expected to be base64-encoded. **pbkdf2_sha256_django:** This is the Django-specific variant of PBKDF2 and the digest should have the following format (as exported from Django): `pbkdf2_sha256$<iterations>$<salt>$<hash>` Note: The salt is expected to be un-encoded, the hash is expected base64-encoded. **pbkdf2_sha1:** This is similar to pkbdf2_sha256_django, but with two differences: 1. uses sha1 instead of sha256 2. accepts the hash as a hex-encoded string The format is the following: `pbkdf2_sha1$<iterations>$<salt>$<hash-as-hex-string>` **phpass:** Portable public domain password hashing framework for use in PHP applications. Digests hashed with phpass have the following sections: The format is the following: `$P$<rounds><salt><encoded-checksum>` - $P$ is the prefix used to identify phpass hashes. - rounds is a single character encoding a 6-bit integer representing the number of rounds used. - salt is eight characters drawn from [./0-9A-Za-z], providing a 48-bit salt. - checksum is 22 characters drawn from the same set, encoding the 128-bit checksum with MD5. **scrypt_firebase:** The Firebase-specific variant of scrypt. The value is expected to have 6 segments separated by the $ character and include the following information: _hash:_ The actual Base64 hash. This can be retrieved when exporting the user from Firebase. _salt:_ The salt used to generate the above hash. Again, this is given when exporting the user. _signer key:_ The base64 encoded signer key. _salt separator:_ The base64 encoded salt separator. _rounds:_ The number of rounds the algorithm needs to run. _memory cost:_ The cost of the algorithm run The first 2 (hash and salt) are per user and can be retrieved when exporting the user from Firebase. The other 4 values (signer key, salt separator, rounds and memory cost) are project-wide settings and can be retrieved from the project's password hash parameters. Once you have all these, you can combine it in the following format and send this as the digest in order for Clerk to accept it: `<hash>$<salt>$<signer key>$<salt separator>$<rounds>$<memory cost>` **argon2i:** Algorithms in the argon2 family generate digests that encode the following information: _version (v):_ The argon version, version 19 is assumed _memory (m):_ The memory used by the algorithm (in kibibytes) _iterations (t):_ The number of iterations to perform _parallelism (p):_ The number of threads to use Parts are demarcated by the `$` character, with the first part identifying the algorithm variant. The middle part is a comma-separated list of the encoding options (memory, iterations, parallelism). The final part is the actual digest. `$argon2i$v=19$m=4096,t=3,p=1$4t6CL3P7YiHBtwESXawI8Hm20zJj4cs7/4/G3c187e0$m7RQFczcKr5bIR0IIxbpO2P0tyrLjf3eUW3M3QSwnLc` **argon2id:** See the previous algorithm for an explanation of the formatting. For the argon2id case, the value of the algorithm in the first part of the digest is `argon2id`: `$argon2id$v=19$m=64,t=4,p=8$Z2liZXJyaXNo$iGXEpMBTDYQ8G/71tF0qGjxRHEmR3gpGULcE93zUJVU` **sha256** (insecure): The digest should be a 64-length hex string, e.g.: `9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08`
120#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
121pub enum PasswordHasher {
122 #[serde(rename = "argon2i")]
123 Argon2i,
124 #[serde(rename = "argon2id")]
125 Argon2id,
126 #[serde(rename = "bcrypt")]
127 Bcrypt,
128 #[serde(rename = "bcrypt_sha256_django")]
129 BcryptSha256Django,
130 #[serde(rename = "md5")]
131 Md5,
132 #[serde(rename = "pbkdf2_sha256")]
133 Pbkdf2Sha256,
134 #[serde(rename = "pbkdf2_sha256_django")]
135 Pbkdf2Sha256Django,
136 #[serde(rename = "pbkdf2_sha1")]
137 Pbkdf2Sha1,
138 #[serde(rename = "phpass")]
139 Phpass,
140 #[serde(rename = "scrypt_firebase")]
141 ScryptFirebase,
142 #[serde(rename = "sha256")]
143 Sha256,
144}
145
146impl Default for PasswordHasher {
147 fn default() -> PasswordHasher {
148 Self::Argon2i
149 }
150}