@@ -2731,8 +2731,11 @@ where
27312731 api_auth
27322732 }
27332733}
2734- #[ derive( Debug ) ]
2735- pub struct PublishableKeyAuth ;
2734+ #[ derive( Debug , Default ) ]
2735+ pub struct PublishableKeyAuth {
2736+ pub is_connected_allowed : bool ,
2737+ pub is_platform_allowed : bool ,
2738+ }
27362739
27372740#[ cfg( feature = "partial-auth" ) ]
27382741impl GetAuthType for PublishableKeyAuth {
@@ -2744,10 +2747,10 @@ impl GetAuthType for PublishableKeyAuth {
27442747#[ cfg( feature = "partial-auth" ) ]
27452748impl GetMerchantAccessFlags for PublishableKeyAuth {
27462749 fn get_is_connected_allowed ( & self ) -> bool {
2747- false // Publishable key doesn't support connected merchant operations currently
2750+ self . is_connected_allowed
27482751 }
27492752 fn get_is_platform_allowed ( & self ) -> bool {
2750- false // Publishable key doesn't support platform merchant operations currently
2753+ self . is_platform_allowed
27512754 }
27522755}
27532756
@@ -2762,29 +2765,45 @@ where
27622765 request_headers : & HeaderMap ,
27632766 state : & A ,
27642767 ) -> RouterResult < ( AuthenticationData , AuthenticationType ) > {
2765- if state. conf ( ) . platform . enabled {
2766- throw_error_if_platform_merchant_authentication_required ( request_headers) ?;
2767- }
2768-
27692768 let publishable_key =
27702769 get_api_key ( request_headers) . change_context ( errors:: ApiErrorResponse :: Unauthorized ) ?;
2771- state
2770+
2771+ // Find initiator merchant and key store
2772+ let ( initiator_merchant, key_store) = state
27722773 . store ( )
27732774 . find_merchant_account_by_publishable_key ( publishable_key)
27742775 . await
2775- . to_not_found_response ( errors:: ApiErrorResponse :: Unauthorized )
2776- . map ( |( merchant_account, key_store) | {
2777- let merchant_id = merchant_account. get_id ( ) . clone ( ) ;
2778- (
2779- AuthenticationData {
2780- merchant_account,
2781- platform_account_with_key_store : None ,
2782- key_store,
2783- profile_id : None ,
2784- } ,
2785- AuthenticationType :: PublishableKey { merchant_id } ,
2786- )
2787- } )
2776+ . to_not_found_response ( errors:: ApiErrorResponse :: Unauthorized ) ?;
2777+
2778+ // Check access permissions using existing function
2779+ check_merchant_access (
2780+ state,
2781+ initiator_merchant. merchant_account_type ,
2782+ self . is_connected_allowed ,
2783+ self . is_platform_allowed ,
2784+ ) ?;
2785+
2786+ // Resolve merchant relationships using existing function
2787+ let ( merchant, key_store, platform_account_with_key_store) =
2788+ resolve_merchant_accounts_and_key_stores (
2789+ state,
2790+ request_headers,
2791+ initiator_merchant. clone ( ) ,
2792+ key_store,
2793+ )
2794+ . await ?;
2795+
2796+ Ok ( (
2797+ AuthenticationData {
2798+ merchant_account : merchant,
2799+ platform_account_with_key_store,
2800+ key_store,
2801+ profile_id : None ,
2802+ } ,
2803+ AuthenticationType :: PublishableKey {
2804+ merchant_id : initiator_merchant. get_id ( ) . clone ( ) ,
2805+ } ,
2806+ ) )
27882807 }
27892808}
27902809
@@ -2805,25 +2824,51 @@ where
28052824 get_id_type_by_key_from_headers ( headers:: X_PROFILE_ID . to_string ( ) , request_headers) ?
28062825 . get_required_value ( headers:: X_PROFILE_ID ) ?;
28072826
2808- let ( merchant_account, key_store) = state
2827+ // Find initiator merchant and key store
2828+ let ( initiator_merchant, key_store) = state
28092829 . store ( )
28102830 . find_merchant_account_by_publishable_key ( publishable_key)
28112831 . await
28122832 . to_not_found_response ( errors:: ApiErrorResponse :: Unauthorized ) ?;
2813- let merchant_id = merchant_account. get_id ( ) . clone ( ) ;
2833+
2834+ // Check access permissions using existing function
2835+ check_merchant_access (
2836+ state,
2837+ initiator_merchant. merchant_account_type ,
2838+ self . is_connected_allowed ,
2839+ self . is_platform_allowed ,
2840+ ) ?;
2841+
2842+ // Resolve merchant relationships using existing function
2843+ let ( merchant, key_store, platform_account_with_key_store) =
2844+ resolve_merchant_accounts_and_key_stores (
2845+ state,
2846+ request_headers,
2847+ initiator_merchant. clone ( ) ,
2848+ key_store,
2849+ )
2850+ . await ?;
2851+
2852+ // Find and validate profile after merchant resolution
28142853 let profile = state
28152854 . store ( )
2816- . find_business_profile_by_merchant_id_profile_id ( & key_store, & merchant_id, & profile_id)
2855+ . find_business_profile_by_merchant_id_profile_id (
2856+ & key_store,
2857+ merchant. get_id ( ) ,
2858+ & profile_id,
2859+ )
28172860 . await
28182861 . to_not_found_response ( errors:: ApiErrorResponse :: Unauthorized ) ?;
28192862 Ok ( (
28202863 AuthenticationData {
2821- merchant_account,
2864+ merchant_account : merchant,
2865+ platform_account_with_key_store,
28222866 key_store,
28232867 profile,
2824- platform_account_with_key_store : None ,
28252868 } ,
2826- AuthenticationType :: PublishableKey { merchant_id } ,
2869+ AuthenticationType :: PublishableKey {
2870+ merchant_id : initiator_merchant. get_id ( ) . clone ( ) ,
2871+ } ,
28272872 ) )
28282873 }
28292874}
@@ -4228,7 +4273,10 @@ pub fn get_auth_type_and_flow<A: SessionStateInfo + Sync + Send>(
42284273
42294274 if api_key. starts_with ( "pk_" ) {
42304275 return Ok ( (
4231- Box :: new ( HeaderAuth ( PublishableKeyAuth ) ) ,
4276+ Box :: new ( HeaderAuth ( PublishableKeyAuth {
4277+ is_connected_allowed : api_auth. is_connected_allowed ,
4278+ is_platform_allowed : api_auth. is_platform_allowed ,
4279+ } ) ) ,
42324280 api:: AuthFlow :: Client ,
42334281 ) ) ;
42344282 }
@@ -4257,7 +4305,10 @@ where
42574305 field_name : "client_secret" ,
42584306 } ) ?;
42594307 return Ok ( (
4260- Box :: new ( HeaderAuth ( PublishableKeyAuth ) ) ,
4308+ Box :: new ( HeaderAuth ( PublishableKeyAuth {
4309+ is_connected_allowed : api_auth. is_connected_allowed ,
4310+ is_platform_allowed : api_auth. is_platform_allowed ,
4311+ } ) ) ,
42614312 api:: AuthFlow :: Client ,
42624313 ) ) ;
42634314 }
0 commit comments