Skip to content

Commit

Permalink
Replace TokenResponse generic with associated type
Browse files Browse the repository at this point in the history
This change slightly simplifies types throughout this crate by removing
a generic type parameter in many places that already have a generic type
representing a `TokenResponse`.

BREAKING CHANGES:
 - Removes `TT` type parameter from `TokenResponse` and
   `TokenIntrospectionResponse` traits trait and adds a `TokenType`
   associated type to each trait.
 - Removes (now-redundant) `TT` type parameter from `Client` and each
   `*Response` type
  • Loading branch information
ramosbugs committed Apr 12, 2024
1 parent e2e8a62 commit 30ced32
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 228 deletions.
16 changes: 16 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,22 @@ the root. For example, if you were previously importing
`oauth2::devicecode::DeviceAuthorizationResponse`, instead import
`oauth2::DeviceAuthorizationResponse`.

### Replace `TT` generic type parameter in `TokenResponse` with associated type

Previously, the `TokenResponse` and `TokenIntrospectionResponse` traits had a generic type
parameter `TT: TokenType`. This has been replaced with an associated type called `TokenType`.
Uses of `BasicTokenResponse` and `BasicTokenIntrospectionResponse` should continue to work without
changes, but custom implementations of either trait will need to be updated to replace the type
parameter with an associated type.

#### Remove `TT` generic type parameter from `Client` and each `*Request` type

Removing the `TT` generic type parameter from `TokenResponse` (see above) made the `TT` parameters
to `Client` and each `*Request` (e.g., `CodeTokenRequest`) redundant. Consequently, the `TT`
parameter has been removed from each of these types. `BasicClient` should continue to work
without any changes, but code that provides generic types for `Client` or any of the `*Response`
types will need to be updated to remove the `TT` type parameter.

### Add `Display` to `ErrorResponse` trait

To improve error messages, the
Expand Down
7 changes: 3 additions & 4 deletions examples/wunderlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use oauth2::basic::{
BasicTokenType,
};
use oauth2::reqwest;
use oauth2::StandardRevocableToken;
use oauth2::{
AccessToken, AuthUrl, AuthorizationCode, Client, ClientId, ClientSecret, CsrfToken,
EmptyExtraTokenFields, EndpointNotSet, ExtraTokenFields, RedirectUrl, RefreshToken, Scope,
TokenResponse, TokenUrl,
};
use oauth2::{StandardRevocableToken, TokenType};
use serde::{Deserialize, Serialize};
use url::Url;

Expand All @@ -43,7 +43,6 @@ type SpecialClient<
> = Client<
BasicErrorResponse,
SpecialTokenResponse,
BasicTokenType,
BasicTokenIntrospectionResponse,
StandardRevocableToken,
BasicRevocationErrorResponse,
Expand Down Expand Up @@ -88,11 +87,11 @@ pub struct NonStandardTokenResponse<EF: ExtraTokenFields> {
extra_fields: EF,
}

impl<EF> TokenResponse<BasicTokenType> for NonStandardTokenResponse<EF>
impl<EF> TokenResponse for NonStandardTokenResponse<EF>
where
EF: ExtraTokenFields,
BasicTokenType: TokenType,
{
type TokenType = BasicTokenType;
/// REQUIRED. The access token issued by the authorization server.
fn access_token(&self) -> &AccessToken {
&self.access_token
Expand Down
1 change: 0 additions & 1 deletion src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub type BasicClient<
> = Client<
BasicErrorResponse,
BasicTokenResponse,
BasicTokenType,
BasicTokenIntrospectionResponse,
StandardRevocableToken,
BasicRevocationErrorResponse,
Expand Down
Loading

0 comments on commit 30ced32

Please sign in to comment.