Skip to content

Commit 30ced32

Browse files
committed
Replace TokenResponse generic with associated type
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
1 parent e2e8a62 commit 30ced32

File tree

11 files changed

+143
-228
lines changed

11 files changed

+143
-228
lines changed

UPGRADE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,22 @@ the root. For example, if you were previously importing
200200
`oauth2::devicecode::DeviceAuthorizationResponse`, instead import
201201
`oauth2::DeviceAuthorizationResponse`.
202202

203+
### Replace `TT` generic type parameter in `TokenResponse` with associated type
204+
205+
Previously, the `TokenResponse` and `TokenIntrospectionResponse` traits had a generic type
206+
parameter `TT: TokenType`. This has been replaced with an associated type called `TokenType`.
207+
Uses of `BasicTokenResponse` and `BasicTokenIntrospectionResponse` should continue to work without
208+
changes, but custom implementations of either trait will need to be updated to replace the type
209+
parameter with an associated type.
210+
211+
#### Remove `TT` generic type parameter from `Client` and each `*Request` type
212+
213+
Removing the `TT` generic type parameter from `TokenResponse` (see above) made the `TT` parameters
214+
to `Client` and each `*Request` (e.g., `CodeTokenRequest`) redundant. Consequently, the `TT`
215+
parameter has been removed from each of these types. `BasicClient` should continue to work
216+
without any changes, but code that provides generic types for `Client` or any of the `*Response`
217+
types will need to be updated to remove the `TT` type parameter.
218+
203219
### Add `Display` to `ErrorResponse` trait
204220

205221
To improve error messages, the

examples/wunderlist.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ use oauth2::basic::{
1919
BasicTokenType,
2020
};
2121
use oauth2::reqwest;
22+
use oauth2::StandardRevocableToken;
2223
use oauth2::{
2324
AccessToken, AuthUrl, AuthorizationCode, Client, ClientId, ClientSecret, CsrfToken,
2425
EmptyExtraTokenFields, EndpointNotSet, ExtraTokenFields, RedirectUrl, RefreshToken, Scope,
2526
TokenResponse, TokenUrl,
2627
};
27-
use oauth2::{StandardRevocableToken, TokenType};
2828
use serde::{Deserialize, Serialize};
2929
use url::Url;
3030

@@ -43,7 +43,6 @@ type SpecialClient<
4343
> = Client<
4444
BasicErrorResponse,
4545
SpecialTokenResponse,
46-
BasicTokenType,
4746
BasicTokenIntrospectionResponse,
4847
StandardRevocableToken,
4948
BasicRevocationErrorResponse,
@@ -88,11 +87,11 @@ pub struct NonStandardTokenResponse<EF: ExtraTokenFields> {
8887
extra_fields: EF,
8988
}
9089

91-
impl<EF> TokenResponse<BasicTokenType> for NonStandardTokenResponse<EF>
90+
impl<EF> TokenResponse for NonStandardTokenResponse<EF>
9291
where
9392
EF: ExtraTokenFields,
94-
BasicTokenType: TokenType,
9593
{
94+
type TokenType = BasicTokenType;
9695
/// REQUIRED. The access token issued by the authorization server.
9796
fn access_token(&self) -> &AccessToken {
9897
&self.access_token

src/basic.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub type BasicClient<
1717
> = Client<
1818
BasicErrorResponse,
1919
BasicTokenResponse,
20-
BasicTokenType,
2120
BasicTokenIntrospectionResponse,
2221
StandardRevocableToken,
2322
BasicRevocationErrorResponse,

0 commit comments

Comments
 (0)