Skip to content

Commit d164954

Browse files
authored
fix(router): Take merchant ID from headers in API Key - Revoke (v2) (#8808)
1 parent 4d4a81e commit d164954

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

crates/router/src/core/api_keys.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,18 +425,18 @@ pub async fn update_api_key_expiry_task(
425425
#[instrument(skip_all)]
426426
pub async fn revoke_api_key(
427427
state: SessionState,
428-
merchant_id: &common_utils::id_type::MerchantId,
428+
merchant_id: common_utils::id_type::MerchantId,
429429
key_id: &common_utils::id_type::ApiKeyId,
430430
) -> RouterResponse<api::RevokeApiKeyResponse> {
431431
let store = state.store.as_ref();
432432

433433
let api_key = store
434-
.find_api_key_by_merchant_id_key_id_optional(merchant_id, key_id)
434+
.find_api_key_by_merchant_id_key_id_optional(&merchant_id, key_id)
435435
.await
436436
.to_not_found_response(errors::ApiErrorResponse::ApiKeyNotFound)?;
437437

438438
let revoked = store
439-
.revoke_api_key(merchant_id, key_id)
439+
.revoke_api_key(&merchant_id, key_id)
440440
.await
441441
.to_not_found_response(errors::ApiErrorResponse::ApiKeyNotFound)?;
442442

crates/router/src/routes/api_keys.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ pub async fn api_key_revoke(
243243
state,
244244
&req,
245245
(&merchant_id, &key_id),
246-
|state, _, (merchant_id, key_id), _| api_keys::revoke_api_key(state, merchant_id, key_id),
246+
|state, _, (merchant_id, key_id), _| {
247+
api_keys::revoke_api_key(state, merchant_id.clone(), key_id)
248+
},
247249
auth::auth_type(
248250
&auth::PlatformOrgAdminAuthWithMerchantIdFromRoute {
249251
merchant_id_from_route: merchant_id.clone(),
@@ -265,24 +267,25 @@ pub async fn api_key_revoke(
265267
pub async fn api_key_revoke(
266268
state: web::Data<AppState>,
267269
req: HttpRequest,
268-
path: web::Path<(
269-
common_utils::id_type::MerchantId,
270-
common_utils::id_type::ApiKeyId,
271-
)>,
270+
path: web::Path<common_utils::id_type::ApiKeyId>,
272271
) -> impl Responder {
273272
let flow = Flow::ApiKeyRevoke;
274-
let (merchant_id, key_id) = path.into_inner();
273+
let key_id = path.into_inner();
275274

276275
Box::pin(api::server_wrap(
277276
flow,
278277
state,
279278
&req,
280-
(&merchant_id, &key_id),
281-
|state, _, (merchant_id, key_id), _| api_keys::revoke_api_key(state, merchant_id, key_id),
279+
&key_id,
280+
|state,
281+
auth::AuthenticationDataWithoutProfile {
282+
merchant_account, ..
283+
},
284+
key_id,
285+
_| api_keys::revoke_api_key(state, merchant_account.get_id().to_owned(), key_id),
282286
auth::auth_type(
283-
&auth::V2AdminApiAuth,
284-
&auth::JWTAuthMerchantFromRoute {
285-
merchant_id: merchant_id.clone(),
287+
&auth::AdminApiAuthWithMerchantIdFromHeader,
288+
&auth::JWTAuthMerchantFromHeader {
286289
required_permission: Permission::MerchantApiKeyWrite,
287290
},
288291
req.headers(),

0 commit comments

Comments
 (0)