pub async fn from_existing<'a, C>(
        http_client: &'a C,
        access_token: AccessToken,
        refresh_token: impl Into<Option<RefreshToken>>,
        client_secret: impl Into<Option<ClientSecret>>,
    ) -> Result<UserToken, ValidationError<<C as Client<'a>>::Error>>
    where
        C: Client<'a>,
    {
        let validated = crate::validate_token(http_client, &access_token).await?;
        Ok(Self::from_existing_unchecked(
            access_token,
            refresh_token.into(),
            validated.client_id,
            client_secret,
            validated.login.ok_or(ValidationError::NoLogin)?,
            validated.user_id.ok_or(ValidationError::NoLogin)?,
            validated.scopes,
            Some(validated.expires_in).filter(|d| {
                // FIXME: https://github.com/rust-lang/rust/pull/84084
                // FIXME: nanos are not returned
                // if duration is zero, the token will never expire. if the token was expired, twitch would return NotAuthorized
                // TODO: There could be a situation where this fails, if the token is just about to expire, say 500ms, does twitch round up to 1 or down to 0?
                !(d.as_secs() == 0 && d.as_nanos() == 0)
            }),
        ))
    }
/// Assemble token and validate it. Retrieves [`login`](TwitchToken::login), [`client_id`](TwitchToken::client_id) and [`scopes`](TwitchToken::scopes)
///
/// If the token is already expired, this function will fail to produce a [`UserToken`] and return [`ValidationError::NotAuthorized`]
Assemble token and validate it.
Assemble token and validate it .
pub async fn from_existing<'a, C>(
        http_client: &'a C,
        access_token: AccessToken,
        refresh_token: impl Into<Option<RefreshToken>>,
        client_secret: impl Into<Option<ClientSecret>>,
    ) -> Result<UserToken, ValidationError<<C as Client<'a>>::Error>>
    where
        C: Client<'a>,
    {
        let validated = crate::validate_token(http_client, &access_token).await?;
        Ok(Self::from_existing_unchecked(
            access_token,
            refresh_token.into(),
            validated.client_id,
            client_secret,
            validated.login.ok_or(ValidationError::NoLogin)?,
            validated.user_id.ok_or(ValidationError::NoLogin)?,
            validated.scopes,
            Some(validated.expires_in).filter(|d| {
                // FIXME: https://github.com/rust-lang/rust/pull/84084
                // FIXME: nanos are not returned
                // if duration is zero, the token will never expire. if the token was expired, twitch would return NotAuthorized
                // TODO: There could be a situation where this fails, if the token is just about to expire, say 500ms, does twitch round up to 1 or down to 0?
                !(d.as_secs() == 0 && d.as_nanos() == 0)
            }),
        ))
    }
pub async fn from_existing < ' a , C > ( http_client : & ' a C , access_token : AccessToken , refresh_token : impl Into < Option < RefreshToken > > , client_secret : impl Into < Option < ClientSecret > > , ) -> Result < UserToken , ValidationError < < C as Client < ' a > > :: Error > > where C : Client < ' a > , { let validated = crate :: validate_token ( http_client , & access_token ) . await ? ; Ok ( Self :: from_existing_unchecked ( access_token , refresh_token . into ( ) , validated . client_id , client_secret , validated . login . ok_or ( ValidationError :: NoLogin ) ? , validated . user_id . ok_or ( ValidationError :: NoLogin ) ? , validated . scopes , Some ( validated . expires_in ) . filter ( | d | { // FIXME: https://github.com/rust-lang/rust/pull/84084 // FIXME: nanos are not returned // if duration is zero, the token will never expire. if the token was expired, twitch would return NotAuthorized // TODO: There could be a situation where this fails, if the token is just about to expire, say 500ms, does twitch round up to 1 or down to 0? ! ( d . as_secs ( ) == 0 && d . as_nanos ( ) == 0 ) } ) , ) ) }
Assemble token and validate it.
Assemble token and validate it .
http_client
&'a C
access_token
AccessToken
refresh_token
impl Into<Option<RefreshToken>>
client_secret
impl Into<Option<ClientSecret>>