pub async fn refresh_token<'a, C>(
    http_client: &'a C,
    refresh_token: &RefreshTokenRef,
    client_id: &ClientId,
    client_secret: &ClientSecret,
) -> Result<
    (AccessToken, std::time::Duration, Option<RefreshToken>),
    RefreshTokenError<<C as Client<'a>>::Error>,
>
where
    C: Client<'a>,
{
    use http::{HeaderMap, Method};
    use std::collections::HashMap;

    let mut params = HashMap::new();
    params.insert("client_id", client_id.as_str());
    params.insert("client_secret", client_secret.secret());
    params.insert("grant_type", "refresh_token");
    params.insert("refresh_token", refresh_token.secret());

    let req = construct_request(
        &crate::TOKEN_URL,
        &params,
        HeaderMap::new(),
        Method::POST,
        vec![],
    );

    let resp = http_client
        .req(req)
        .await
        .map_err(RefreshTokenError::RequestError)?;
    let res: id::TwitchTokenResponse = parse_response(&resp)?;

    let expires_in = res.expires_in().ok_or(RefreshTokenError::NoExpiration)?;
    let refresh_token = res.refresh_token;
    let access_token = res.access_token;
    Ok((access_token, expires_in, refresh_token))
}
/// Refresh the token, call if it has expired.
///
/// See <https://dev.twitch.tv/docs/authentication#refreshing-access-tokens>
Refresh the token, call if it has expired.
See
Refresh the token call if it has expired . See
pub async fn refresh_token<'a, C>(
    http_client: &'a C,
    refresh_token: &RefreshTokenRef,
    client_id: &ClientId,
    client_secret: &ClientSecret,
) -> Result<
    (AccessToken, std::time::Duration, Option<RefreshToken>),
    RefreshTokenError<<C as Client<'a>>::Error>,
>
where
    C: Client<'a>,
{
    use http::{HeaderMap, Method};
    use std::collections::HashMap;
    let mut params = HashMap::new();
    params.insert("client_id", client_id.as_str());
    params.insert("client_secret", client_secret.secret());
    params.insert("grant_type", "refresh_token");
    params.insert("refresh_token", refresh_token.secret());
    let req = construct_request(
        &crate::TOKEN_URL,
        &params,
        HeaderMap::new(),
        Method::POST,
        vec![],
    );
    let resp = http_client
        .req(req)
        .await
        .map_err(RefreshTokenError::RequestError)?;
    let res: id::TwitchTokenResponse = parse_response(&resp)?;
    let expires_in = res.expires_in().ok_or(RefreshTokenError::NoExpiration)?;
    let refresh_token = res.refresh_token;
    let access_token = res.access_token;
    Ok((access_token, expires_in, refresh_token))
}
pub async fn refresh_token < ' a , C > ( http_client : & ' a C , refresh_token : & RefreshTokenRef , client_id : & ClientId , client_secret : & ClientSecret , ) -> Result < ( AccessToken , std :: time :: Duration , Option < RefreshToken > ) , RefreshTokenError < < C as Client < ' a > > :: Error > , > where C : Client < ' a > , { use http :: { HeaderMap , Method } ; use std :: collections :: HashMap ; let mut params = HashMap :: new ( ) ; params . insert ( " " , client_id . as_str ( ) ) ; params . insert ( " " , client_secret . secret ( ) ) ; params . insert ( " " , " " ) ; params . insert ( " " , refresh_token . secret ( ) ) ; let req = construct_request ( & crate :: TOKEN_URL , & params , HeaderMap :: new ( ) , Method :: POST , vec ! [ ] , ) ; let resp = http_client . req ( req ) . await . map_err ( RefreshTokenError :: RequestError ) ? ; let res : id :: TwitchTokenResponse = parse_response ( & resp ) ? ; let expires_in = res . expires_in ( ) . ok_or ( RefreshTokenError :: NoExpiration ) ? ; let refresh_token = res . refresh_token ; let access_token = res . access_token ; Ok ( ( access_token , expires_in , refresh_token ) ) }
Refresh the token, call if it has expired.
Refresh the token call if it has expired .
http_client
&'a C
refresh_token
&RefreshTokenRef
client_id
&ClientId
client_secret
&ClientSecret