yew_oauth2/agent/
ops.rs

1use super::{AgentConfiguration, Client, LoginOptions, LogoutOptions};
2use std::fmt::{Display, Formatter};
3
4/// Operation error
5#[derive(Clone, Debug)]
6pub enum Error {
7    /// The agent cannot be reached.
8    NoAgent,
9}
10
11impl Display for Error {
12    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
13        match self {
14            Self::NoAgent => write!(f, "no agent"),
15        }
16    }
17}
18
19impl std::error::Error for Error {}
20
21/// Operations for the OAuth2 agent
22pub trait OAuth2Operations<C: Client> {
23    /// Configure the agent with a configuration.
24    ///
25    /// This is normally done by the [`crate::components::context::OAuth2`] context component.
26    fn configure(&self, config: AgentConfiguration<C>) -> Result<(), Error>;
27
28    /// Start a login flow with default options.
29    fn start_login(&self) -> Result<(), Error>;
30
31    /// Start a login flow.
32    fn start_login_opts(&self, options: LoginOptions) -> Result<(), Error>;
33
34    /// Trigger the logout with default options.
35    fn logout(&self) -> Result<(), Error>;
36
37    /// Trigger the logout.
38    fn logout_opts(&self, options: LogoutOptions) -> Result<(), Error>;
39}