66
77use std:: collections:: BTreeMap ;
88
9- use mas_iana:: { jose:: JsonWebSignatureAlg , oauth :: OAuthClientAuthenticationMethod } ;
9+ use mas_iana:: jose:: JsonWebSignatureAlg ;
1010use schemars:: JsonSchema ;
1111use serde:: { de:: Error , Deserialize , Serialize } ;
1212use serde_with:: skip_serializing_none;
@@ -48,7 +48,9 @@ impl ConfigurationSection for UpstreamOAuth2Config {
4848 } ;
4949
5050 match provider. token_endpoint_auth_method {
51- TokenAuthMethod :: None | TokenAuthMethod :: PrivateKeyJwt => {
51+ TokenAuthMethod :: None
52+ | TokenAuthMethod :: PrivateKeyJwt
53+ | TokenAuthMethod :: SignInWithApple => {
5254 if provider. client_secret . is_some ( ) {
5355 return annotate ( figment:: Error :: custom ( "Unexpected field `client_secret` for the selected authentication method" ) ) ;
5456 }
@@ -65,7 +67,8 @@ impl ConfigurationSection for UpstreamOAuth2Config {
6567 match provider. token_endpoint_auth_method {
6668 TokenAuthMethod :: None
6769 | TokenAuthMethod :: ClientSecretBasic
68- | TokenAuthMethod :: ClientSecretPost => {
70+ | TokenAuthMethod :: ClientSecretPost
71+ | TokenAuthMethod :: SignInWithApple => {
6972 if provider. token_endpoint_auth_signing_alg . is_some ( ) {
7073 return annotate ( figment:: Error :: custom (
7174 "Unexpected field `token_endpoint_auth_signing_alg` for the selected authentication method" ,
@@ -80,6 +83,22 @@ impl ConfigurationSection for UpstreamOAuth2Config {
8083 }
8184 }
8285 }
86+
87+ match provider. token_endpoint_auth_method {
88+ TokenAuthMethod :: SignInWithApple => {
89+ if provider. sign_in_with_apple . is_none ( ) {
90+ return annotate ( figment:: Error :: missing_field ( "sign_in_with_apple" ) ) ;
91+ }
92+ }
93+
94+ _ => {
95+ if provider. sign_in_with_apple . is_some ( ) {
96+ return annotate ( figment:: Error :: custom (
97+ "Unexpected field `sign_in_with_apple` for the selected authentication method" ,
98+ ) ) ;
99+ }
100+ }
101+ }
83102 }
84103
85104 Ok ( ( ) )
@@ -108,20 +127,9 @@ pub enum TokenAuthMethod {
108127 /// `private_key_jwt`: a `client_assertion` sent in the request body and
109128 /// signed by an asymmetric key
110129 PrivateKeyJwt ,
111- }
112130
113- impl From < TokenAuthMethod > for OAuthClientAuthenticationMethod {
114- fn from ( method : TokenAuthMethod ) -> Self {
115- match method {
116- TokenAuthMethod :: None => OAuthClientAuthenticationMethod :: None ,
117- TokenAuthMethod :: ClientSecretBasic => {
118- OAuthClientAuthenticationMethod :: ClientSecretBasic
119- }
120- TokenAuthMethod :: ClientSecretPost => OAuthClientAuthenticationMethod :: ClientSecretPost ,
121- TokenAuthMethod :: ClientSecretJwt => OAuthClientAuthenticationMethod :: ClientSecretJwt ,
122- TokenAuthMethod :: PrivateKeyJwt => OAuthClientAuthenticationMethod :: PrivateKeyJwt ,
123- }
124- }
131+ /// `sign_in_with_apple`: a special method for Signin with Apple
132+ SignInWithApple ,
125133}
126134
127135/// How to handle a claim
@@ -343,6 +351,18 @@ fn is_default_true(value: &bool) -> bool {
343351 * value
344352}
345353
354+ #[ derive( Debug , Clone , Serialize , Deserialize , JsonSchema ) ]
355+ pub struct SignInWithApple {
356+ /// The private key used to sign the `id_token`
357+ pub private_key : String ,
358+
359+ /// The Team ID of the Apple Developer Portal
360+ pub team_id : String ,
361+
362+ /// The key ID of the Apple Developer Portal
363+ pub key_id : String ,
364+ }
365+
346366#[ skip_serializing_none]
347367#[ derive( Debug , Clone , Serialize , Deserialize , JsonSchema ) ]
348368pub struct Provider {
@@ -394,6 +414,10 @@ pub struct Provider {
394414 /// The method to authenticate the client with the provider
395415 pub token_endpoint_auth_method : TokenAuthMethod ,
396416
417+ /// Additional parameters for the `sign_in_with_apple` method
418+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
419+ pub sign_in_with_apple : Option < SignInWithApple > ,
420+
397421 /// The JWS algorithm to use when authenticating the client with the
398422 /// provider
399423 ///
0 commit comments