pub struct Credentials<Id> {
pub id: Id,
pub secret: String,
}Expand description
Authentication credentials containing a user identifier and plaintext secret.
This type represents raw login input at the authentication boundary. It stores the caller-provided identifier together with a plaintext secret so a verifier can compare it against stored authentication material.
§Type Parameter
Id: Identifier type used by the calling application, commonlyStringoruuid::Uuid
§Security
- The
secretfield contains plaintext sensitive data. - Keep instances short-lived and avoid cloning them unnecessarily.
- Never log, persist, or expose the raw secret.
- Use secure transport when credentials cross process or network boundaries.
§Examples
Create credentials from application input:
use webgates_core::credentials::Credentials;
let credentials = Credentials::new(&"user@example.com".to_string(), "user_password");
assert_eq!(credentials.id, "user@example.com");
assert_eq!(credentials.secret, "user_password");Deserialize credentials from JSON:
use webgates_core::credentials::Credentials;
let json = r#"{"id":"user@example.com","secret":"password123"}"#;
let credentials: Credentials<String> = serde_json::from_str(json)?;
assert_eq!(credentials.id, "user@example.com");Use a UUID identifier:
use uuid::Uuid;
use webgates_core::credentials::Credentials;
let user_id = Uuid::now_v7();
let credentials = Credentials::new(&user_id, "user_password");
assert_eq!(credentials.id, user_id);Fields§
§id: IdUser identifier, such as a username, email address, or UUID.
secret: StringPlaintext secret supplied by the caller, such as a password.
Implementations§
Source§impl<Id> Credentials<Id>
impl<Id> Credentials<Id>
Sourcepub fn new(id: &Id, secret: &str) -> Selfwhere
Id: ToOwned<Owned = Id>,
pub fn new(id: &Id, secret: &str) -> Selfwhere
Id: ToOwned<Owned = Id>,
Creates credentials from an identifier and a plaintext secret.
The identifier is cloned into the returned value and the secret is stored
as an owned String.
§Parameters
id: User identifier to copy into the credentialssecret: Plaintext secret supplied by the caller
§Security
The returned value contains plaintext sensitive data. Callers should keep it short-lived and avoid logging or persisting it.
§Examples
use webgates_core::credentials::Credentials;
let credentials = Credentials::new(&"admin@company.com".to_string(), "admin_password");
assert_eq!(credentials.id, "admin@company.com");
assert_eq!(credentials.secret, "admin_password");use uuid::Uuid;
use webgates_core::credentials::Credentials;
let user_id = Uuid::now_v7();
let credentials = Credentials::new(&user_id, "user_secret");
assert_eq!(credentials.id, user_id);Trait Implementations§
Source§impl<Id: Clone> Clone for Credentials<Id>
impl<Id: Clone> Clone for Credentials<Id>
Source§fn clone(&self) -> Credentials<Id>
fn clone(&self) -> Credentials<Id>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more