summaryrefslogtreecommitdiff
path: root/src/auth
diff options
context:
space:
mode:
Diffstat (limited to 'src/auth')
-rw-r--r--src/auth/mod.rs44
1 files changed, 2 insertions, 42 deletions
diff --git a/src/auth/mod.rs b/src/auth/mod.rs
index fae0383..ce550e1 100644
--- a/src/auth/mod.rs
+++ b/src/auth/mod.rs
@@ -11,12 +11,11 @@ use tokio::task::JoinHandle;
use tokio::{select, spawn};
use crate::auth::service::retrieve_auth_code;
-use crate::errors::auth::{AccessTokenRequestError, AuthPromptHandlerError};
+use crate::errors::auth::AuthPromptHandlerError;
mod service;
const AUTH_URL: &str = "https://connect.deezer.com/oauth/auth.php";
-const ACCESS_TOKEN_URL: &str = "https://connect.deezer.com/oauth/access_token.php";
/// A Deezer authentication code.
#[derive(Debug, Deserialize, Clone)]
@@ -96,7 +95,7 @@ impl AuthPromptHandler
}
/// A Deezer access token.
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct AccessToken
{
/// The access token.
@@ -105,42 +104,3 @@ pub struct AccessToken
/// The duration until the access token expires.
pub expires: Duration,
}
-
-/// Sends a request for a access token.
-///
-/// # Errors
-/// Will return Err if either sending the request fails or parsing the response fails.
-pub async fn request_access_token(
- app_id: u32,
- secret_key: String,
- auth_code: AuthCode,
-) -> Result<AccessToken, AccessTokenRequestError>
-{
- let response = reqwest::get(format!(
- "{}?app_id={}&secret={}&code={}&output=json",
- ACCESS_TOKEN_URL, app_id, secret_key, auth_code
- ))
- .await?
- .json::<AccessTokenResponse>()
- .await?;
-
- Ok(response.into())
-}
-
-#[derive(Debug, Deserialize)]
-struct AccessTokenResponse
-{
- pub access_token: String,
- pub expires: u64,
-}
-
-impl From<AccessTokenResponse> for AccessToken
-{
- fn from(response: AccessTokenResponse) -> Self
- {
- Self {
- access_token: response.access_token,
- expires: Duration::from_secs(response.expires),
- }
- }
-}