Skip to content

Commit

Permalink
Flatten more structs
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxuser committed Dec 19, 2023
1 parent b999b31 commit 519c3ad
Show file tree
Hide file tree
Showing 8 changed files with 532 additions and 525 deletions.
2 changes: 1 addition & 1 deletion examples/src/bin/auth_azure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tokio::{
};
use xal::{
client_params::CLIENT_ANDROID,
flows::{AuthPromptCallback, AuthPromptData},
AuthPromptCallback, AuthPromptData,
oauth2::{RedirectUrl, Scope},
url::Url,
Error, XalAppParameters,
Expand Down
4 changes: 2 additions & 2 deletions examples/src/bin/auth_cli.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use xal::{flows, AccessTokenPrefix, Error};
use xal::{CliCallbackHandler, AccessTokenPrefix, Error};
use xal_examples::auth_main_default;

#[tokio::main]
async fn main() -> Result<(), Error> {
auth_main_default(AccessTokenPrefix::None, flows::CliCallbackHandler)
auth_main_default(AccessTokenPrefix::None, CliCallbackHandler)
.await
.ok();

Expand Down
4 changes: 2 additions & 2 deletions examples/src/bin/auth_minecraft.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde_json::json;
use xal::{
extensions::JsonExDeserializeMiddleware, flows, oauth2::TokenResponse, AccessTokenPrefix,
extensions::JsonExDeserializeMiddleware, CliCallbackHandler, oauth2::TokenResponse, AccessTokenPrefix,
Error, XalAuthenticator,
};
use xal_examples::auth_main;
Expand All @@ -15,7 +15,7 @@ async fn main() -> Result<(), Error> {
client_params,
"RETAIL".into(),
AccessTokenPrefix::None,
flows::CliCallbackHandler,
CliCallbackHandler,
)
.await?;

Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/auth_webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use wry::{
webview::WebViewBuilder,
};
use xal::{
flows::{AuthPromptCallback, AuthPromptData},
AuthPromptCallback, AuthPromptData,
url::Url,
AccessTokenPrefix, Error, XalAuthenticator,
};
Expand Down
24 changes: 12 additions & 12 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use clap::{Parser, ValueEnum};
use env_logger::Env;
use log::info;
use xal::{
flows, tokenstore::TokenStore, AccessTokenPrefix, Constants, Error, XalAppParameters,
XalAuthenticator, XalClientParameters,
Flows, TokenStore, AccessTokenPrefix, Constants, Error, XalAppParameters,
XalAuthenticator, XalClientParameters, AuthPromptCallback
};

/// Common cli arguments
Expand Down Expand Up @@ -57,7 +57,7 @@ pub enum AuthFlow {

pub async fn auth_main_default(
access_token_prefix: AccessTokenPrefix,
auth_cb: impl flows::AuthPromptCallback,
auth_cb: impl AuthPromptCallback,
) -> Result<TokenStore, Error> {
auth_main(
XalAppParameters::default(),
Expand All @@ -75,22 +75,22 @@ pub async fn auth_main(
client_params: XalClientParameters,
sandbox_id: String,
access_token_prefix: AccessTokenPrefix,
auth_cb: impl flows::AuthPromptCallback,
auth_cb: impl AuthPromptCallback,
) -> Result<TokenStore, Error> {
let args = handle_args();

let mut ts = match flows::try_refresh_live_tokens_from_file(&args.token_filepath).await {
let mut ts = match Flows::try_refresh_live_tokens_from_file(&args.token_filepath).await {
Ok((mut authenticator, ts)) => {
info!("Tokens refreshed succesfully, proceeding with Xbox Live Authorization");
match args.flow {
AuthFlow::Sisu => {
info!("Authorize and gather rest of xbox live tokens via sisu");
flows::xbox_live_sisu_authorization_flow(&mut authenticator, ts.live_token)
Flows::xbox_live_sisu_authorization_flow(&mut authenticator, ts.live_token)
.await?
}
_ => {
info!("Authorize Xbox Live the traditional way, via individual requests");
flows::xbox_live_authorization_traditional_flow(
Flows::xbox_live_authorization_traditional_flow(
&mut authenticator,
ts.live_token,
Constants::RELYING_PARTY_XBOXLIVE.into(),
Expand All @@ -108,17 +108,17 @@ pub async fn auth_main(
info!("Authentication via flow={:?}", args.flow);
let ts = match args.flow {
AuthFlow::Sisu => {
flows::xbox_live_sisu_full_flow(&mut authenticator, auth_cb).await?
Flows::xbox_live_sisu_full_flow(&mut authenticator, auth_cb).await?
}
AuthFlow::DeviceCode => {
flows::ms_device_code_flow(&mut authenticator, auth_cb, tokio::time::sleep)
Flows::ms_device_code_flow(&mut authenticator, auth_cb, tokio::time::sleep)
.await?
}
AuthFlow::Implicit => {
flows::ms_authorization_flow(&mut authenticator, auth_cb, true).await?
Flows::ms_authorization_flow(&mut authenticator, auth_cb, true).await?
}
AuthFlow::AuthorizationCode => {
flows::ms_authorization_flow(&mut authenticator, auth_cb, false).await?
Flows::ms_authorization_flow(&mut authenticator, auth_cb, false).await?
}
};

Expand All @@ -128,7 +128,7 @@ pub async fn auth_main(
info!("Continuing flow via traditional Xbox Live authorization");
// Only required for non-sisu authentication, as
// sisu already gathers all the tokens at once
flows::xbox_live_authorization_traditional_flow(
Flows::xbox_live_authorization_traditional_flow(
&mut authenticator,
ts.live_token,
Constants::RELYING_PARTY_XBOXLIVE.into(),
Expand Down
Loading

0 comments on commit 519c3ad

Please sign in to comment.