Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/agent/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub enum OAuth2Error {
StartLogin(String),
/// Failed to handle login result
LoginResult(String),
/// Silent login found no active session (not a real error)
LoginRequired,
/// Failed to handle token refresh
Refresh(String),
/// Failing storing information
Expand All @@ -27,6 +29,7 @@ impl Display for OAuth2Error {
Self::Configuration(err) => write!(f, "configuration error: {err}"),
Self::StartLogin(err) => write!(f, "start login error: {err}"),
Self::LoginResult(err) => write!(f, "login result: {err}"),
Self::LoginRequired => f.write_str("login required"),
Self::Refresh(err) => write!(f, "refresh error: {err}"),
Self::Storage(err) => write!(f, "storage error: {err}"),
Self::Internal(err) => write!(f, "internal error: {err}"),
Expand All @@ -38,7 +41,12 @@ impl std::error::Error for OAuth2Error {}

impl From<OAuth2Error> for OAuth2Context {
fn from(err: OAuth2Error) -> Self {
OAuth2Context::Failed(err.to_string())
match err {
OAuth2Error::LoginRequired => OAuth2Context::NotAuthenticated {
reason: crate::context::Reason::LoginRequired,
},
other => OAuth2Context::Failed(other.to_string()),
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,10 @@ where
// cleanup URL
Self::cleanup_url();

if error == "login_required" || error == "interaction_required" {
return Err(OAuth2Error::LoginRequired);
}

// error from the OAuth2 server
return Err(OAuth2Error::LoginResult(error));
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/redirect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ where
let _ = agent.start_login();
}
}
Reason::LoginRequired => {
// silent login (prompt=none) found no active session — do nothing,
// let the app handle this as NotAuthenticated
}
Reason::Expired | Reason::Logout => {
match self.auth {
None | Some(OAuth2Context::NotInitialized) => {
Expand Down
2 changes: 2 additions & 0 deletions src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub enum Reason {
Expired,
/// Because the user chose to log out.
Logout,
/// Silent login (prompt=none) found no active session.
LoginRequired,
}

/// A handle to access the latest access token.
Expand Down