Skip to main content

Credentials

Struct Credentials 

Source
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, commonly String or uuid::Uuid

§Security

  • The secret field 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: Id

User identifier, such as a username, email address, or UUID.

§secret: String

Plaintext secret supplied by the caller, such as a password.

Implementations§

Source§

impl<Id> Credentials<Id>

Source

pub fn new(id: &Id, secret: &str) -> Self
where 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 credentials
  • secret: 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>

Source§

fn clone(&self) -> Credentials<Id>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Id: Debug> Debug for Credentials<Id>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, Id> Deserialize<'de> for Credentials<Id>
where Id: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Id> Serialize for Credentials<Id>
where Id: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<Id> Freeze for Credentials<Id>
where Id: Freeze,

§

impl<Id> RefUnwindSafe for Credentials<Id>
where Id: RefUnwindSafe,

§

impl<Id> Send for Credentials<Id>
where Id: Send,

§

impl<Id> Sync for Credentials<Id>
where Id: Sync,

§

impl<Id> Unpin for Credentials<Id>
where Id: Unpin,

§

impl<Id> UnsafeUnpin for Credentials<Id>
where Id: UnsafeUnpin,

§

impl<Id> UnwindSafe for Credentials<Id>
where Id: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,