pub struct AuthProvider { /* private fields */ }Expand description
Provides API key retrieval and HTTP request authentication for the CLI.
API key resolution order:
- Environment variable
APCORE_AUTH_API_KEY - Config resolver
auth.api_keyfield (may bekeyring:orenc:prefixed) - Return
Noneif neither is present.
Implementations§
Source§impl AuthProvider
impl AuthProvider
Sourcepub fn new(config: ConfigResolver) -> Self
pub fn new(config: ConfigResolver) -> Self
Create a new AuthProvider with the given configuration resolver.
Sourcepub fn get_api_key(&self) -> Option<String>
pub fn get_api_key(&self) -> Option<String>
Retrieve the API key using the resolution order above.
Returns None when no key is found.
Sourcepub fn authenticate_request(
&self,
builder: RequestBuilder,
) -> Result<RequestBuilder, AuthenticationError>
pub fn authenticate_request( &self, builder: RequestBuilder, ) -> Result<RequestBuilder, AuthenticationError>
Inject the Authorization header into the given request builder.
§Errors
Returns AuthenticationError::MissingApiKey if no key is found.
Sourcepub fn check_status_code(&self, status: u16) -> Result<(), AuthenticationError>
pub fn check_status_code(&self, status: u16) -> Result<(), AuthenticationError>
Check an HTTP status code for authentication errors.
Returns Ok(()) for non-auth-error codes, Err(InvalidApiKey) for 401/403.
This is the testable core of handle_response.
Sourcepub fn handle_response(
&self,
response: Response,
) -> Result<Response, AuthenticationError>
pub fn handle_response( &self, response: Response, ) -> Result<Response, AuthenticationError>
Inspect an HTTP response for 401/403 codes and raise the appropriate error.
Returns the response unchanged if authentication succeeded.
Auto Trait Implementations§
impl Freeze for AuthProvider
impl RefUnwindSafe for AuthProvider
impl Send for AuthProvider
impl Sync for AuthProvider
impl Unpin for AuthProvider
impl UnsafeUnpin for AuthProvider
impl UnwindSafe for AuthProvider
Blanket Implementations§
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