Flows

Struct Flows 

Source
pub struct Flows;
Expand description

Higher-level, bundled functionality for common authentication tasks

Implementations§

Source§

impl Flows

Source

pub async fn try_refresh_live_tokens_from_file( filepath: &str, ) -> Result<(XalAuthenticator, TokenStore), Error>

Try to deserialize a JSON TokenStore from filepath and refresh the Windows Live tokens if needed.

§Errors

This function may return an error if the file cannot be read, fails to deserialize or the tokens cannot be refreshed.

§Examples

// Refresh Windows Live tokens first
let (mut authenticator, token_store) = Flows::try_refresh_live_tokens_from_file("tokens.json")
    .await?;

// Continue by requesting xbox live tokens
let token_store = Flows::xbox_live_sisu_authorization_flow(
    &mut authenticator,
    token_store.live_token
)
.await?;
§Returns

If successful, a tuple of crate::XalAuthenticator and crate::tokenstore::TokenStore is returned. TokenStore will contain the refreshed live_tokens.

Source

pub async fn try_refresh_live_tokens_from_tokenstore( ts: &mut TokenStore, ) -> Result<XalAuthenticator, Error>

Try to read tokens from the token store and refresh the Windows Live tokens if needed.

§Examples
use std::fs::File;
use serde_json;
use xal::{Flows, TokenStore};

let mut file = File::open("tokens.json")
    .expect("Failed to open tokenfile");
let mut ts: TokenStore = serde_json::from_reader(&mut file)
    .expect("Failed to deserialize TokenStore");

let authenticator = Flows::try_refresh_live_tokens_from_tokenstore(&mut ts)
    .await
    .expect("Failed refreshing Windows Live tokens");
§Errors

This function may return an error if the token store cannot be read or the tokens cannot be refreshed.

§Returns

If successful, a tuple of crate::XalAuthenticator and crate::TokenStore is returned. TokenStore will contain the refreshed live_tokens.

Source

pub async fn ms_device_code_flow<S, SF>( authenticator: &mut XalAuthenticator, cb: impl AuthPromptCallback, sleep_fn: S, ) -> Result<TokenStore, Error>
where S: Fn(Duration) -> SF, SF: Future<Output = ()>,

Shorthand for Windows Live device code flow

§Examples
use xal::{XalAuthenticator, Flows, Error, AccessTokenPrefix, CliCallbackHandler};
use xal::response::WindowsLiveTokens;


let mut authenticator = XalAuthenticator::default();

let token_store = Flows::ms_device_code_flow(
    &mut authenticator,
    CliCallbackHandler,
    async_sleep_fn
)
.await?;

// TokenStore will only contain live tokens
assert!(token_store.user_token.is_none());
assert!(token_store.title_token.is_none());
assert!(token_store.device_token.is_none());
assert!(token_store.authorization_token.is_none());
Source

pub async fn ms_authorization_flow( authenticator: &mut XalAuthenticator, cb: impl AuthPromptCallback, implicit: bool, ) -> Result<TokenStore, Error>

Shorthand for Windows Live authorization flow

  • Depending on the argument implicit the methods implicit grant or authorization code are chosen
§Examples
use xal::{XalAuthenticator, Flows, Error, AccessTokenPrefix, CliCallbackHandler};
use xal::response::WindowsLiveTokens;

let do_implicit_flow = true;
let mut authenticator = XalAuthenticator::default();

let token_store = Flows::ms_authorization_flow(
    &mut authenticator,
    CliCallbackHandler,
    do_implicit_flow,
)
.await?;

// TokenStore will only contain live tokens
assert!(token_store.user_token.is_none());
assert!(token_store.title_token.is_none());
assert!(token_store.device_token.is_none());
assert!(token_store.authorization_token.is_none());
Source

pub async fn xbox_live_sisu_full_flow( authenticator: &mut XalAuthenticator, callback: impl AuthPromptCallback, ) -> Result<TokenStore, Error>

Shorthand for sisu authentication flow

§Examples
use xal::{XalAuthenticator, Flows, Error, CliCallbackHandler};

let mut authenticator = XalAuthenticator::default();

let token_store = Flows::xbox_live_sisu_full_flow(
    &mut authenticator,
    CliCallbackHandler,
)
.await?;

// TokenStore will contain user/title/device/xsts tokens
assert!(token_store.user_token.is_some());
assert!(token_store.title_token.is_some());
assert!(token_store.device_token.is_some());
assert!(token_store.authorization_token.is_some());
Source

pub async fn xbox_live_authorization_traditional_flow( authenticator: &mut XalAuthenticator, live_tokens: WindowsLiveTokens, xsts_relying_party: String, access_token_prefix: AccessTokenPrefix, request_title_token: bool, ) -> Result<TokenStore, Error>

Implements the traditional Xbox Live authorization flow.

The method serves as a shorthand for executing the Xbox Live authorization flow by exchanging crate::models::response::WindowsLiveTokens to ultimately acquire an authorized Xbox Live session.

The authorization flow is designed to be highly modular, allowing for extensive customization based on the specific needs of your application.

§Arguments
  • xsts_relying_party XSTS Relying Party URL (see #Notes)
  • access_token_prefix Whether AccessToken needs to be prefixed for the Xbox UserToken (XASU) Request (see #Notes).
  • request_title_token Whether to request a Title Token (see #Notes)
§Errors

This method may return an error if any of the intermediate token requests fail. For a more detailed explanation of the error, refer to the documentation of the crate::XalAuthenticator methods.

§Returns

This method returns a Result containing a tuple with two elements:

  • The updated XalAuthenticator instance, with an incremented crate::cvlib::CorrelationVector
  • A TokenStore struct, with all the tokens necessary exchanged during the authorization flow.
§Examples
use xal::{XalAuthenticator, Flows, CliCallbackHandler, Error, AccessTokenPrefix};
use xal::response::WindowsLiveTokens;

let mut authenticator = XalAuthenticator::default();

let token_store = Flows::ms_device_code_flow(
    &mut authenticator,
    CliCallbackHandler,
    tokio::time::sleep
)
.await?;

// Execute the Xbox Live authorization flow..
let token_store = Flows::xbox_live_authorization_traditional_flow(
    &mut authenticator,
    token_store.live_token,
    "rp://api.minecraftservices.com/".to_string(),
    AccessTokenPrefix::D,
    true,
)
.await?;
§Notes
  • Requesting a Title Token standalone aka. without sisu-flow only works for very few clients, currently only “Minecraft” is known.
  • Depending on the client an AccessToken prefix is necessary to have the User Token (XASU) request succeed
  • Success of authorizing (device, user, ?title?) tokens for XSTS relies on the target relying party
Source

pub async fn xbox_live_sisu_authorization_flow( authenticator: &mut XalAuthenticator, live_tokens: WindowsLiveTokens, ) -> Result<TokenStore, Error>

The authorization part of Sisu

§Examples
use xal::{XalAuthenticator, Flows, CliCallbackHandler, Error, AccessTokenPrefix};
use xal::response::WindowsLiveTokens;

let mut authenticator = XalAuthenticator::default();

let token_store = Flows::ms_device_code_flow(
    &mut authenticator,
    CliCallbackHandler,
    tokio::time::sleep
)
.await?;

let token_store = Flows::xbox_live_sisu_authorization_flow(
    &mut authenticator,
    token_store.live_token,
)
.await?;

// TokenStore will contain user/title/device/xsts tokens
assert!(token_store.user_token.is_some());
assert!(token_store.title_token.is_some());
assert!(token_store.device_token.is_some());
assert!(token_store.authorization_token.is_some());

Auto Trait Implementations§

§

impl Freeze for Flows

§

impl RefUnwindSafe for Flows

§

impl Send for Flows

§

impl Sync for Flows

§

impl Unpin for Flows

§

impl UnwindSafe for Flows

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,