pub struct OAuth2AuthorizationCodeBearerConfig {
pub authorization_url: String,
pub token_url: String,
pub refresh_url: Option<String>,
pub scopes: HashMap<String, String>,
pub scheme_name: Option<String>,
pub description: Option<String>,
pub auto_error: bool,
}Expand description
Configuration for OAuth2 authorization code bearer extraction.
This configures the authorization code flow for OpenAPI documentation.
The actual token extraction is identical to OAuth2PasswordBearer —
the difference is in the OpenAPI security scheme generated.
§Example
use fastapi_core::OAuth2AuthorizationCodeBearerConfig;
let config = OAuth2AuthorizationCodeBearerConfig::new(
"https://auth.example.com/authorize",
"https://auth.example.com/token",
)
.with_refresh_url("https://auth.example.com/refresh")
.with_scope("read", "Read access")
.with_scope("write", "Write access");Fields§
URL for the authorization endpoint. Required for OpenAPI documentation.
token_url: StringURL for the token endpoint. Required for OpenAPI documentation.
refresh_url: Option<String>URL to refresh the token. Optional.
scopes: HashMap<String, String>OAuth2 scopes with their descriptions.
scheme_name: Option<String>Custom scheme name for OpenAPI documentation.
description: Option<String>Description for OpenAPI documentation.
auto_error: boolWhether to automatically return 401 on missing/invalid token. Default: true.
Implementations§
Source§impl OAuth2AuthorizationCodeBearerConfig
impl OAuth2AuthorizationCodeBearerConfig
Sourcepub fn new(
authorization_url: impl Into<String>,
token_url: impl Into<String>,
) -> Self
pub fn new( authorization_url: impl Into<String>, token_url: impl Into<String>, ) -> Self
Create a new configuration with the given authorization and token URLs.
Sourcepub fn with_refresh_url(self, url: impl Into<String>) -> Self
pub fn with_refresh_url(self, url: impl Into<String>) -> Self
Set the refresh URL.
Sourcepub fn with_scope(
self,
scope: impl Into<String>,
description: impl Into<String>,
) -> Self
pub fn with_scope( self, scope: impl Into<String>, description: impl Into<String>, ) -> Self
Add an OAuth2 scope.
Sourcepub fn with_scheme_name(self, name: impl Into<String>) -> Self
pub fn with_scheme_name(self, name: impl Into<String>) -> Self
Set the scheme name for OpenAPI.
Sourcepub fn with_description(self, desc: impl Into<String>) -> Self
pub fn with_description(self, desc: impl Into<String>) -> Self
Set the description for OpenAPI.
Sourcepub fn with_auto_error(self, auto_error: bool) -> Self
pub fn with_auto_error(self, auto_error: bool) -> Self
Set whether to auto-error on missing/invalid tokens.
Trait Implementations§
Source§impl Clone for OAuth2AuthorizationCodeBearerConfig
impl Clone for OAuth2AuthorizationCodeBearerConfig
Source§fn clone(&self) -> OAuth2AuthorizationCodeBearerConfig
fn clone(&self) -> OAuth2AuthorizationCodeBearerConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more