use serde::{Deserialize, Serialize};
use crate::{
error::{ApiError, check_response},
url::FirebaseUrl,
};
pub async fn refresh_id_token(
firebase_url: &FirebaseUrl,
refresh_token: &str,
) -> Result<RefreshIdTokenResponse, ApiError> {
let client = reqwest::Client::new();
let response = client
.post(&firebase_url.token_url)
.header("Content-Type", "application/json")
.json(&Payload {
grant_type: "refresh_token",
refresh_token,
})
.send()
.await?;
check_response(response).await
}
#[derive(Debug, Serialize)]
struct Payload<'a> {
grant_type: &'a str,
refresh_token: &'a str,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct RefreshIdTokenResponse {
pub access_token: String,
pub expires_in: String,
pub token_type: String,
pub refresh_token: String,
pub id_token: String,
pub user_id: String,
pub project_id: String,
}