Open Closed

ABP API is throwing 400 bad request error rather than redirecting to login page #9667


User avatar
0
manas-patnaik_HON created

When I try to authorize for accessing the ABP swagger api documentation, it is throwing 400 bad request error rather than going to login page. API has been hosted in Azure App service.


2 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • A 400 Bad Request error during Swagger authorization in ABP (especially when hosted on Azure App Service) is often caused by a mismatch or misconfiguration in the OAuth/OpenId Connect client settings, particularly the redirect URI.

    To resolve this:

    1. Check Redirect URI Configuration

      • Ensure the redirect URI registered for your Swagger client in the IdentityServer/OpenIddict configuration matches exactly with the URI used by Swagger UI in Azure.
      • For example, if your Swagger UI is at https://your-app.azurewebsites.net/swagger/oauth2-redirect.html, this exact URI must be registered as a valid redirect URI for the Swagger client.
    2. Update Client Settings

      • Update the client configuration in your DbMigrator's appsettings.json and/or in your database (OpenIddict/IdentityServer client table) to include the correct redirect URI.
      • After updating, clear any distributed cache (e.g., Redis) if used.
    3. Remove Client Secret for Swagger

      • Swagger is a public client and should not require a client secret. Remove the client secret from the Swagger client configuration.
    4. Restart Services

      • After making changes, restart your API and ensure the changes are applied.
    5. Verify with Correct URL

      • Access Swagger at the deployed Azure URL and attempt authorization again.

    Example configuration for Swagger client in appsettings.json:

    "Swagger": {
      "ClientId": "YourApp_Swagger",
      "RootUrl": "https://your-app.azurewebsites.net"
    }
    

    And in your client seeding logic:

    await CreateClientAsync(
      name: "YourApp_Swagger",
      grantTypes: new[] { "authorization_code" },
      requireClientSecret: false,
      redirectUri: "https://your-app.azurewebsites.net/swagger/oauth2-redirect.html",
      corsOrigins: new[] { "https://your-app.azurewebsites.net" }
    );
    

    If you still encounter issues, double-check that the redirect URI in the error message matches exactly with what is registered.

    Sources:


    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share the debug logs(logs.txt) when 400 bad request error?

    https://abp.io/support/questions/8622/How-to-enable-Debug-logs-for-troubleshoot-problems

    liming.ma@volosoft.com

    Thanks.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on September 18, 2025, 07:10