Skip to content

Commit

Permalink
style: rename ClientMetadataEnum to ClientMetadataResource
Browse files Browse the repository at this point in the history
  • Loading branch information
nanderstabel committed Mar 15, 2024
1 parent dfda52b commit 88d556a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion oid4vc-core/src/client_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use url::Url;
#[skip_serializing_none]
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ClientMetadataEnum<T = ()> {
pub enum ClientMetadataResource<T = ()> {
// TODO: Add all fields described in https://www.rfc-editor.org/rfc/rfc7591.html#section-2
ClientMetadata {
client_name: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions oid4vc-manager/tests/siopv2/implicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use lazy_static::lazy_static;
use oid4vc_core::{
authorization_request::{AuthorizationRequest, ByReference, Object},
authorization_response::AuthorizationResponse,
client_metadata::ClientMetadataEnum,
client_metadata::ClientMetadataResource,
scope::{Scope, ScopeValue},
DidMethod, SubjectSyntaxType,
};
Expand Down Expand Up @@ -70,7 +70,7 @@ async fn test_implicit_flow() {
.scope(Scope::from(vec![ScopeValue::OpenId, ScopeValue::Phone]))
.redirect_uri(format!("{server_url}/redirect_uri").parse::<url::Url>().unwrap())
.response_mode("direct_post".to_string())
.client_metadata(ClientMetadataEnum::<ClientMetadataParameters>::ClientMetadata {
.client_metadata_resource(ClientMetadataResource::<ClientMetadataParameters>::ClientMetadata {
client_name: None,
logo_uri: None,
extension: ClientMetadataParameters {
Expand Down
19 changes: 11 additions & 8 deletions oid4vp/src/authorization_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use monostate::MustBe;
use oid4vc_core::authorization_request::Object;
use oid4vc_core::builder_fn;
use oid4vc_core::{
authorization_request::AuthorizationRequest, client_metadata::ClientMetadataEnum, scope::Scope, RFC7519Claims,
authorization_request::AuthorizationRequest, client_metadata::ClientMetadataResource, scope::Scope, RFC7519Claims,
};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
Expand Down Expand Up @@ -37,7 +37,7 @@ pub struct AuthorizationRequestParameters {
pub scope: Option<Scope>,
pub nonce: String,
#[serde(flatten)]
pub client_metadata: Option<ClientMetadataEnum<ClientMetadataParameters>>,
pub client_metadata_resource: Option<ClientMetadataResource<ClientMetadataParameters>>,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
Expand All @@ -59,7 +59,7 @@ pub struct AuthorizationRequestBuilder {
scope: Option<Scope>,
response_mode: Option<String>,
nonce: Option<String>,
client_metadata: Option<ClientMetadataEnum<ClientMetadataParameters>>,
client_metadata_resource: Option<ClientMetadataResource<ClientMetadataParameters>>,
}

impl AuthorizationRequestBuilder {
Expand All @@ -75,7 +75,10 @@ impl AuthorizationRequestBuilder {
builder_fn!(scope, Scope);
builder_fn!(redirect_uri, url::Url);
builder_fn!(nonce, String);
builder_fn!(client_metadata, ClientMetadataEnum<ClientMetadataParameters>);
builder_fn!(
client_metadata_resource,
ClientMetadataResource<ClientMetadataParameters>
);
builder_fn!(state, String);
builder_fn!(presentation_definition, PresentationDefinition);
builder_fn!(client_id_scheme, ClientIdScheme);
Expand All @@ -97,7 +100,7 @@ impl AuthorizationRequestBuilder {
.nonce
.take()
.ok_or_else(|| anyhow!("nonce parameter is required."))?,
client_metadata: self.client_metadata.take(),
client_metadata_resource: self.client_metadata_resource.take(),
};

Ok(AuthorizationRequest::<Object<OID4VP>> {
Expand Down Expand Up @@ -172,7 +175,7 @@ mod tests {
#[test]
fn test_oid4vp_examples() {
// Examples from
// https://github.com/openid/OpenID4VP/tree/965597ae01fc6e6a2bddc0d6b16f3f6122f3c1ab/examples/client_metadata.
// https://github.com/openid/OpenID4VP/tree/965597ae01fc6e6a2bddc0d6b16f3f6122f3c1ab/examples/client_metadata_resource.

// Some required parameters are omitted in the examples. Therefore this example struct represents a subset of
// the full `AuthorizationRequestParameters` struct.
Expand All @@ -188,7 +191,7 @@ mod tests {
// pub nonce: String,
// TODO: impl client_metadata_uri.
#[serde(flatten)]
pub client_metadata: Option<ClientMetadataEnum<ClientMetadataParameters>>,
pub client_metadata_resource: Option<ClientMetadataResource<ClientMetadataParameters>>,
}

assert_eq!(
Expand All @@ -199,7 +202,7 @@ mod tests {
client_id_scheme: None,
response_mode: None,
scope: None,
client_metadata: Some(ClientMetadataEnum::ClientMetadata {
client_metadata_resource: Some(ClientMetadataResource::ClientMetadata {
client_name: Some("My Example (SIOP)".to_string()),
logo_uri: None,
extension: ClientMetadataParameters {
Expand Down
27 changes: 15 additions & 12 deletions siopv2/src/authorization_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use monostate::MustBe;
use oid4vc_core::authorization_request::Object;
use oid4vc_core::builder_fn;
use oid4vc_core::{
authorization_request::AuthorizationRequest, client_metadata::ClientMetadataEnum, scope::Scope, RFC7519Claims,
authorization_request::AuthorizationRequest, client_metadata::ClientMetadataResource, scope::Scope, RFC7519Claims,
SubjectSyntaxType,
};
use serde::{Deserialize, Serialize};
Expand All @@ -19,9 +19,9 @@ pub struct AuthorizationRequestParameters {
pub response_mode: Option<String>,
pub nonce: String,
pub claims: Option<ClaimRequests>,
// TODO: impl client_metadata_uri.
// TODO: impl client_metadata_resource_uri.
#[serde(flatten)]
pub client_metadata: Option<ClientMetadataEnum<ClientMetadataParameters>>,
pub client_metadata_resource: Option<ClientMetadataResource<ClientMetadataParameters>>,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
Expand All @@ -37,12 +37,12 @@ impl AuthorizationRequestParameters {
}

pub fn subject_syntax_types_supported(&self) -> Option<&Vec<SubjectSyntaxType>> {
self.client_metadata.as_ref().and_then(|r| match r {
ClientMetadataEnum::ClientMetadata { extension, .. } => {
self.client_metadata_resource.as_ref().and_then(|r| match r {
ClientMetadataResource::ClientMetadata { extension, .. } => {
Some(extension.subject_syntax_types_supported.as_ref())
}
// TODO: impl client_metadata_uri.
ClientMetadataEnum::ClientMetadataUri(_) => None,
// TODO: impl client_metadata_resource_uri.
ClientMetadataResource::ClientMetadataUri(_) => None,
})
}

Expand All @@ -68,7 +68,7 @@ pub struct AuthorizationRequestBuilder {
response_mode: Option<String>,
nonce: Option<String>,
claims: Option<Result<ClaimRequests>>,
client_metadata: Option<ClientMetadataEnum<ClientMetadataParameters>>,
client_metadata_resource: Option<ClientMetadataResource<ClientMetadataParameters>>,
}

impl AuthorizationRequestBuilder {
Expand All @@ -89,7 +89,10 @@ impl AuthorizationRequestBuilder {
builder_fn!(scope, Scope);
builder_fn!(redirect_uri, url::Url);
builder_fn!(nonce, String);
builder_fn!(client_metadata, ClientMetadataEnum<ClientMetadataParameters>);
builder_fn!(
client_metadata_resource,
ClientMetadataResource<ClientMetadataParameters>
);
builder_fn!(state, String);

pub fn build(mut self) -> Result<AuthorizationRequest<Object<SIOPv2>>> {
Expand All @@ -108,7 +111,7 @@ impl AuthorizationRequestBuilder {
.take()
.ok_or_else(|| anyhow!("nonce parameter is required."))?,
claims: self.claims.take().transpose()?,
client_metadata: self.client_metadata.take(),
client_metadata_resource: self.client_metadata_resource.take(),
};

Ok(AuthorizationRequest::<Object<SIOPv2>> {
Expand Down Expand Up @@ -147,7 +150,7 @@ mod tests {
&client_id=did%3Aexample%3AEiDrihTRe0GMdc3K16kgJB3Xbl9Hb8oqVHjzm6ufHcYDGA\
&redirect_uri=https%3A%2F%2Fclient.example.org%2Fcb\
&response_mode=direct_post\
&client_metadata=%7B%22subject_syntax_types_supported%22%3A\
&client_metadata_resource=%7B%22subject_syntax_types_supported%22%3A\
%5B%22did%3Atest%22%5D%2C%0A%20%20%20%20\
%22id_token_signing_alg_values_supported%22%3A%5B%22EdDSA%22%5D%7D\
&nonce=n-0S6_WzA2Mj\
Expand Down Expand Up @@ -201,7 +204,7 @@ mod tests {
}),
..Default::default()
}),
client_metadata: None,
client_metadata_resource: None,
},
}
}
Expand Down

0 comments on commit 88d556a

Please sign in to comment.