pub struct ClientConfigBuilder { /* private fields */ }Expand description
Builder for creating ClientConfig instances with fluent API.
Reduces cognitive load when registering OAuth clients with many optional fields.
Required fields are set in new(), optional fields via builder methods.
§Example
use auth_framework::client::{ClientConfig, ClientType};
use auth_framework::types::{RedirectUris, Scopes, GrantTypes, ResponseTypes};
let config = ClientConfig::builder("client123", ClientType::Confidential)
.client_secret("secret456")
.redirect_uris(RedirectUris::new(vec!["https://example.com/callback".to_string()]))
.authorized_scopes(Scopes::new(vec!["read".to_string(), "write".to_string()]))
.client_name("My App")
.build();Implementations§
Source§impl ClientConfigBuilder
impl ClientConfigBuilder
Sourcepub fn new(client_id: impl Into<String>, client_type: ClientType) -> Self
pub fn new(client_id: impl Into<String>, client_type: ClientType) -> Self
Create a new builder with required fields.
Sets sensible defaults for optional fields:
client_secret: Noneredirect_uris: emptyauthorized_scopes: [“read”]authorized_grant_types: [“authorization_code”]authorized_response_types: [“code”]client_name,client_description: Nonemetadata: empty
§Example
use auth_framework::client::{ClientConfigBuilder, ClientType};
let builder = ClientConfigBuilder::new("my-app", ClientType::Public);
let config = builder.build();
assert_eq!(config.client_id, "my-app");Sourcepub fn client_secret(self, client_secret: impl Into<String>) -> Self
pub fn client_secret(self, client_secret: impl Into<String>) -> Self
Set the client secret.
§Example
use auth_framework::client::{ClientConfigBuilder, ClientType};
let config = ClientConfigBuilder::new("app", ClientType::Confidential)
.client_secret("s3cret")
.build();
assert_eq!(config.client_secret.unwrap(), "s3cret");Sourcepub fn redirect_uris(self, redirect_uris: RedirectUris) -> Self
pub fn redirect_uris(self, redirect_uris: RedirectUris) -> Self
Set the authorized redirect URIs.
§Example
use auth_framework::client::{ClientConfigBuilder, ClientType};
use auth_framework::types::RedirectUris;
let config = ClientConfigBuilder::new("app", ClientType::Public)
.redirect_uris(RedirectUris::new(vec!["https://example.com/cb".into()]))
.build();Set the authorized scopes.
§Example
use auth_framework::client::{ClientConfigBuilder, ClientType};
use auth_framework::types::Scopes;
let config = ClientConfigBuilder::new("app", ClientType::Public)
.authorized_scopes(Scopes::new(vec!["read".into(), "write".into()]))
.build();Set the authorized grant types.
§Example
use auth_framework::client::{ClientConfigBuilder, ClientType};
use auth_framework::types::GrantTypes;
let config = ClientConfigBuilder::new("app", ClientType::Confidential)
.authorized_grant_types(GrantTypes::new(vec!["client_credentials".into()]))
.build();Set the authorized response types.
§Example
use auth_framework::client::{ClientConfigBuilder, ClientType};
use auth_framework::types::ResponseTypes;
let config = ClientConfigBuilder::new("app", ClientType::Public)
.authorized_response_types(ResponseTypes::new(vec!["code".into()]))
.build();Sourcepub fn client_name(self, client_name: impl Into<String>) -> Self
pub fn client_name(self, client_name: impl Into<String>) -> Self
Set the client name.
§Example
use auth_framework::client::{ClientConfigBuilder, ClientType};
let config = ClientConfigBuilder::new("app", ClientType::Public)
.client_name("My Application")
.build();
assert_eq!(config.client_name.unwrap(), "My Application");Sourcepub fn client_description(self, client_description: impl Into<String>) -> Self
pub fn client_description(self, client_description: impl Into<String>) -> Self
Set the client description.
§Example
use auth_framework::client::{ClientConfigBuilder, ClientType};
let config = ClientConfigBuilder::new("app", ClientType::Public)
.client_description("OAuth 2.0 demo app")
.build();
assert_eq!(config.client_description.unwrap(), "OAuth 2.0 demo app");Sourcepub fn metadata(self, metadata: HashMap<String, Value>) -> Self
pub fn metadata(self, metadata: HashMap<String, Value>) -> Self
Set the metadata.
§Example
use auth_framework::client::{ClientConfigBuilder, ClientType};
use std::collections::HashMap;
let mut meta = HashMap::new();
meta.insert("logo_uri".into(), serde_json::json!("https://example.com/logo.png"));
let config = ClientConfigBuilder::new("app", ClientType::Public)
.metadata(meta)
.build();
assert!(config.metadata.contains_key("logo_uri"));Sourcepub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
pub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
Add a metadata key-value pair.
§Example
use auth_framework::client::{ClientConfigBuilder, ClientType};
let config = ClientConfigBuilder::new("app", ClientType::Public)
.with_metadata("tos_uri", serde_json::json!("https://example.com/tos"))
.build();
assert!(config.metadata.contains_key("tos_uri"));Sourcepub fn build(self) -> ClientConfig
pub fn build(self) -> ClientConfig
Build the ClientConfig instance.
§Example
use auth_framework::client::{ClientConfigBuilder, ClientType};
let config = ClientConfigBuilder::new("app", ClientType::Public).build();
assert_eq!(config.client_id, "app");Trait Implementations§
Source§impl Clone for ClientConfigBuilder
impl Clone for ClientConfigBuilder
Source§fn clone(&self) -> ClientConfigBuilder
fn clone(&self) -> ClientConfigBuilder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ClientConfigBuilder
impl RefUnwindSafe for ClientConfigBuilder
impl Send for ClientConfigBuilder
impl Sync for ClientConfigBuilder
impl Unpin for ClientConfigBuilder
impl UnsafeUnpin for ClientConfigBuilder
impl UnwindSafe for ClientConfigBuilder
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more