Skip to content

[ENHANCE] create_user_authentication_method API response to include created entity details #9643

@apoorvdixit88

Description

@apoorvdixit88

Currently, the create_user_authentication_method API endpoint (POST /user/auth) returns a generic 200 OK status with an empty body upon successful creation. This is not informative for API clients, who would benefit from receiving the complete details of the newly created resource in the response, rather than just a success status.

Proposed Solution:

To improve the API's usability and provide immediate access to the created resource's data, the endpoint should return a JSON response containing all the relevant fields of the new user authentication method. This aligns with common REST API practices where a POST request to a collection resource returns the representation of the newly created resource.

Implementation Plan:

  1. Define a New Comprehensive Response Struct:

    • In the file crates/api_models/src/user.rs, define a new public struct named CreateUserAuthenticationMethodResponse.

    • This struct should derive Debug, serde::Serialize and any other traits if required.

    • It should contain the following public fields with their respective types:

      • id, auth_id, owner_id,owner_type, auth_type, email_domain,allow_signup
    • Place this new struct definition logically near the existing CreateUserAuthenticationMethodRequest struct.

  2. Update the Core Function:

    • In the file crates/router/src/core/user.rs, locate the create_user_authentication_method async function.
    • Update the function's return type from UserResponse<()> to UserResponse<CreateUserAuthenticationMethodResponse>.
    • Add the necessary import statement at the top of the file: use api_models::user::CreateUserAuthenticationMethodResponse;.
    • Modify the function's success return statement. Instead of Ok(ApplicationResponse::StatusOk), it should return CreateUserAuthenticationMethodResponse. This uses the variables already available or computed within the function to populate the response struct.

How to Test:

  1. Run the Hyperswitch application locally.
  2. Make a POST request to the /user/authentication_method endpoint.
  3. Use the admin API key for authorization. For local development, the key is typically test_admin.
  4. The request body should be a valid CreateUserAuthenticationMethodRequest JSON object.
  5. Verify that the response status is 200 OK and the response body is a JSON object containing the id, auth_id, owner_id, owner_type, auth_type, email_domain, and allow_signup of the newly created authentication method.

Curl

curl --location '<hyperswitch-backend-base-url>/user/auth' \ 
--header 'Content-Type: application/json' \ 
--header 'api-key: <admin-api-key>' \ 
--data ' 
{ 
"owner_type": "organization",  
"owner_id": "test_123",  
    "auth_method": { 
        "auth_type": "open_id_connect", 
        "private_config": { 
            "base_url": "hello.com", 
            "client_id": "something_client", 
            "client_secret": "something_client", 
            "private_key": "something" 
        }, 
        "public_config": { 
            "name": "okta" 
         
    } 
    }, 
    "allow_signup": true,  
    "email_domain": "None" 
}'

Expected Outcome:

After these changes, a successful request to POST /user/auth will yield a 200 OK response with a JSON body similar to the following:

{
  "id": "5500",
  "auth_id": "a1b2c3d4-0-1234-567890abcdef",
  "owner_id": "merchant_123",
  "owner_type": "Merchant",
  "auth_type": "OpenIdConnect",
  "email_domain": "example.com",
  "allow_signup": true
}

This provides a much more robust and developer-friendly API experience by giving clients full visibility into the created resource immediately.

Metadata

Metadata

Assignees

Labels

A-usersArea: UsersE-easyEffort: Should be easy to implement and would make a good first PRenhancementNew feature or requestgood first issueGood for newcomershacktoberfestIssues that are up for grabs for Hacktoberfest participants

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions