Skip to content

Commit

Permalink
Remove unnecessary trait bound on AuthorizationRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
cobward committed Sep 3, 2024
1 parent 74e6b2c commit 890a901
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 35 deletions.
20 changes: 5 additions & 15 deletions src/authorization.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::Cow, marker::PhantomData};
use std::borrow::Cow;

use oauth2::{CsrfToken, PkceCodeChallenge};
use serde::{Deserialize, Serialize};
Expand All @@ -9,25 +9,15 @@ use crate::{
types::{IssuerState, IssuerUrl, UserHint},
};

pub struct AuthorizationRequest<'a, AD>
where
AD: AuthorizationDetailsProfile,
{
pub struct AuthorizationRequest<'a> {
inner: oauth2::AuthorizationRequest<'a>,
_pd: PhantomData<AD>,
}

// TODO 5.1.2 scopes

impl<'a, AD> AuthorizationRequest<'a, AD>
where
AD: AuthorizationDetailsProfile,
{
impl<'a> AuthorizationRequest<'a> {
pub(crate) fn new(inner: oauth2::AuthorizationRequest<'a>) -> Self {
Self {
inner,
_pd: PhantomData,
}
Self { inner }
}

pub fn url(self) -> (Url, CsrfToken) {
Expand All @@ -39,7 +29,7 @@ where
self
}

pub fn set_authorization_details(
pub fn set_authorization_details<AD: AuthorizationDetailsProfile>(
mut self,
authorization_details: Vec<AuthorizationDetail<AD>>,
) -> Result<Self, serde_json::Error> {
Expand Down
10 changes: 4 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
credential_issuer::{CredentialIssuerMetadataDisplay, CredentialMetadata},
AuthorizationServerMetadata, CredentialIssuerMetadata,
},
profiles::{AuthorizationDetailsProfile, Profile},
profiles::Profile,
pushed_authorization::PushedAuthorizationRequest,
token,
types::{BatchCredentialUrl, CredentialUrl, DeferredCredentialUrl, IssuerUrl, ParUrl},
Expand Down Expand Up @@ -117,13 +117,12 @@ where
}
}

pub fn pushed_authorization_request<S, AD>(
pub fn pushed_authorization_request<S>(
&self,
state_fn: S,
) -> Result<PushedAuthorizationRequest<AD>, Error>
) -> Result<PushedAuthorizationRequest, Error>
where
S: FnOnce() -> CsrfToken,
AD: AuthorizationDetailsProfile,
{
let Some(par_url) = self.par_auth_url.as_ref() else {
return Err(Error::ParUnsupported);
Expand All @@ -141,10 +140,9 @@ where
))
}

pub fn authorize_url<S, AD>(&self, state_fn: S) -> Result<AuthorizationRequest<AD>, Error>
pub fn authorize_url<S>(&self, state_fn: S) -> Result<AuthorizationRequest, Error>
where
S: FnOnce() -> CsrfToken,
AD: AuthorizationDetailsProfile,
{
let inner = self
.inner
Expand Down
21 changes: 7 additions & 14 deletions src/pushed_authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,15 @@ pub struct PushedAuthorizationResponse {
pub expires_in: u64,
}

pub struct PushedAuthorizationRequest<'a, AD>
where
AD: AuthorizationDetailsProfile,
{
inner: AuthorizationRequest<'a, AD>,
pub struct PushedAuthorizationRequest<'a> {
inner: AuthorizationRequest<'a>,
par_auth_url: ParUrl,
auth_url: AuthUrl,
}

impl<'a, AD> PushedAuthorizationRequest<'a, AD>
where
AD: AuthorizationDetailsProfile,
{
impl<'a> PushedAuthorizationRequest<'a> {
pub(crate) fn new(
inner: AuthorizationRequest<'a, AD>,
inner: AuthorizationRequest<'a>,
par_auth_url: ParUrl,
auth_url: AuthUrl,
) -> Self {
Expand Down Expand Up @@ -129,7 +123,6 @@ where
where
'a: 'c,
C: AsyncHttpClient<'c>,
AD: 'c,
{
Box::pin(async move {
let mut auth_url = self.auth_url.url().clone();
Expand Down Expand Up @@ -221,7 +214,7 @@ where
self
}

pub fn set_authorization_details(
pub fn set_authorization_details<AD: AuthorizationDetailsProfile>(
mut self,
authorization_details: Vec<AuthorizationDetail<AD>>,
) -> Result<Self, serde_json::Error> {
Expand Down Expand Up @@ -321,10 +314,10 @@ mod test {
let state = CsrfToken::new("state".into());

let (_, body, _) = client
.pushed_authorization_request::<_, CoreProfilesAuthorizationDetails>(move || state)
.pushed_authorization_request(move || state)
.unwrap()
.set_pkce_challenge(pkce_challenge)
.set_authorization_details(vec![])
.set_authorization_details::<CoreProfilesAuthorizationDetails>(vec![])
.unwrap()
.prepare_request()
.unwrap();
Expand Down

0 comments on commit 890a901

Please sign in to comment.