Logout without Exit

This commit is contained in:
2024-10-17 01:11:16 +02:00
parent f93eb3c429
commit d5bc2a700f
3 changed files with 56 additions and 12 deletions

View File

@@ -13,6 +13,7 @@ pub enum State {
config: Config,
},
Authenticate {
open_browser: bool,
code_verifier: CodeVerifier,
code_challenge_method: CodeChallengeMethod,
},
@@ -29,6 +30,7 @@ pub enum Event {
config: Config,
},
StartAuthenticate {
open_browser: bool,
code_verifier: CodeVerifier,
code_challenge_method: CodeChallengeMethod,
}, // should not be string
@@ -46,15 +48,17 @@ impl State {
pub async fn next(self, event: Event) -> State {
match (self, event) {
// (Current State, SomeEvent) => NextState
(State::Init, Event::Ready { config }) => State::AppStart { config },
(_, Event::Ready { config }) => State::AppStart { config },
(
State::AppStart { .. },
Event::StartAuthenticate {
code_verifier: code_challenge,
open_browser,
code_verifier,
code_challenge_method,
},
) => Self::Authenticate {
code_verifier: code_challenge,
open_browser,
code_verifier,
code_challenge_method,
}, // Goto Authenticate
@@ -85,6 +89,7 @@ impl State {
token: token.to_string(),
})?;
} else {
let open_browser = config.open_browser();
let code_verifier = CodeVerifier::new();
let code_challenge_method = CodeChallengeMethod::Sha256;
@@ -92,6 +97,7 @@ impl State {
config.set_code_challenge_method(Some(code_challenge_method.clone()))?;
signal.send(Event::StartAuthenticate {
open_browser,
code_verifier,
code_challenge_method,
})?;
@@ -99,10 +105,13 @@ impl State {
Ok(())
}
State::Authenticate {
open_browser,
code_verifier,
code_challenge_method,
} => {
oauth::open_browser(code_verifier.clone(), code_challenge_method.clone())?;
if *open_browser {
oauth::open_browser(code_verifier.clone(), code_challenge_method.clone())?;
}
Ok(())
}