mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-01-05 10:50:36 +01:00
Revert Token back to AccessToken, as TokenInfo can be used to retrieve id_token
This commit is contained in:
@@ -12,7 +12,7 @@ use crate::refresh::RefreshFlow;
|
||||
#[cfg(feature = "service_account")]
|
||||
use crate::service_account::{self, ServiceAccountFlow, ServiceAccountFlowOpts, ServiceAccountKey};
|
||||
use crate::storage::{self, Storage, TokenStorage};
|
||||
use crate::types::{ApplicationSecret, Token, TokenInfo};
|
||||
use crate::types::{AccessToken, ApplicationSecret, TokenInfo};
|
||||
use private::AuthFlow;
|
||||
|
||||
use crate::access_token::{AccessTokenFlow};
|
||||
@@ -69,7 +69,7 @@ where
|
||||
S::Error: Into<Box<dyn StdError + Send + Sync>>,
|
||||
{
|
||||
/// Return the current token for the provided scopes.
|
||||
pub async fn token<'a, T>(&'a self, scopes: &'a [T]) -> Result<Token, Error>
|
||||
pub async fn token<'a, T>(&'a self, scopes: &'a [T]) -> Result<AccessToken, Error>
|
||||
where
|
||||
T: AsRef<str>,
|
||||
{
|
||||
@@ -80,7 +80,7 @@ where
|
||||
|
||||
/// Return a token for the provided scopes, but don't reuse cached tokens. Instead,
|
||||
/// always fetch a new token from the OAuth server.
|
||||
pub async fn force_refreshed_token<'a, T>(&'a self, scopes: &'a [T]) -> Result<Token, Error>
|
||||
pub async fn force_refreshed_token<'a, T>(&'a self, scopes: &'a [T]) -> Result<AccessToken, Error>
|
||||
where
|
||||
T: AsRef<str>,
|
||||
{
|
||||
|
||||
@@ -111,4 +111,4 @@ pub use crate::service_account::ServiceAccountKey;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use crate::error::Error;
|
||||
pub use crate::types::{ApplicationSecret, ConsoleApplicationSecret, Token};
|
||||
pub use crate::types::{AccessToken, ApplicationSecret, ConsoleApplicationSecret};
|
||||
|
||||
17
src/types.rs
17
src/types.rs
@@ -6,20 +6,15 @@ use serde::{Deserialize, Serialize};
|
||||
/// Represents a token returned by oauth2 servers. All tokens are Bearer tokens. Other types of
|
||||
/// tokens are not supported.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
|
||||
pub struct Token {
|
||||
id_token: Option<String>,
|
||||
pub struct AccessToken {
|
||||
access_token: Option<String>,
|
||||
expires_at: Option<OffsetDateTime>,
|
||||
}
|
||||
|
||||
impl Token {
|
||||
/// A string representation of the ID token.
|
||||
pub fn id_token(&self) -> Option<&str> {
|
||||
self.id_token.as_deref()
|
||||
}
|
||||
impl AccessToken {
|
||||
|
||||
/// A string representation of the access token.
|
||||
pub fn access_token(&self) -> Option<&str> {
|
||||
pub fn token(&self) -> Option<&str> {
|
||||
self.access_token.as_deref()
|
||||
}
|
||||
|
||||
@@ -40,18 +35,16 @@ impl Token {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TokenInfo> for Token {
|
||||
impl From<TokenInfo> for AccessToken {
|
||||
fn from(
|
||||
TokenInfo {
|
||||
access_token,
|
||||
id_token,
|
||||
expires_at,
|
||||
..
|
||||
}: TokenInfo,
|
||||
) -> Self {
|
||||
Token {
|
||||
AccessToken {
|
||||
access_token,
|
||||
id_token,
|
||||
expires_at,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user