Skip to main content

drasi_lib/identity/
password.rs

1// Copyright 2025 The Drasi Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use super::{Credentials, IdentityProvider};
16use anyhow::Result;
17use async_trait::async_trait;
18
19/// Identity provider for traditional username/password authentication.
20#[derive(Clone)]
21pub struct PasswordIdentityProvider {
22    username: String,
23    password: String,
24}
25
26impl PasswordIdentityProvider {
27    /// Create a new password identity provider.
28    pub fn new(username: impl Into<String>, password: impl Into<String>) -> Self {
29        Self {
30            username: username.into(),
31            password: password.into(),
32        }
33    }
34}
35
36#[async_trait]
37impl IdentityProvider for PasswordIdentityProvider {
38    async fn get_credentials(&self) -> Result<Credentials> {
39        Ok(Credentials::UsernamePassword {
40            username: self.username.clone(),
41            password: self.password.clone(),
42        })
43    }
44
45    fn clone_box(&self) -> Box<dyn IdentityProvider> {
46        Box::new(self.clone())
47    }
48}