Open Closed

Cannot login on Swagger API with new project #664


User avatar
0
scott7106 created

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

  • ABP Framework version: v4.0.0

  • UI type: Angular

  • Tiered (MVC) or Identity Server Seperated (Angular): no

  • Steps to reproduce the issue:

  • abp new Acme.BookStore -u angular -m none -csf

  • build the solution

  • run dbmigrator project

  • run httpapi.host project

  • there is no login button shown on the swagger api // attempting to use the /api/account/login post endpoint to login gives an error

  • Exception message and stack trace: 2020-12-10 12:05:25.045 -05:00 [DBG] Error Url: /Account/Error 2020-12-10 12:05:25.045 -05:00 [DBG] Error Id Parameter: errorId 2020-12-10 12:05:25.049 -05:00 [ERR] The required antiforgery cookie ".AspNetCore.Antiforgery.gYxNi6c7Ut0" is not present. 2020-12-10 12:05:25.050 -05:00 [INF] Authorization failed for the request at filter 'Volo.Abp.AspNetCore.Mvc.AntiForgery.AbpAutoValidateAntiforgeryTokenAuthorizationFilter'. 2020-12-10 12:05:25.054 -05:00 [INF] Executing HttpStatusCodeResult, setting HTTP status code 400

There are related tickets/pull requests which were closed indicating this is in v4.0, but testing indicates otherwise

  • https://github.com/abpframework/abp/issues/1874
  • https://github.com/abpframework/abp/issues/5803
  • https://github.com/abpframework/abp/pull/5864

6 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can open /account/login page to login.

    After you login, you need to open the /account/login page again

  • User Avatar
    0
    scott7106 created

    Ok. That works, but it is not obvious. Why not implement the Security Definition and Security Requirements for Swagger in the default template?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    IdentityServer project not need configure security Requirements for Swagger. Because you can login directly

  • User Avatar
    0
    scott7106 created

    Adding the [Authorize] attribute on the home controller eliminates the need to manually navigate to the login page. Since the Swagger UI cannot be used without logging in, you might as well add Authorize.

  • User Avatar
    0
    alper created
    Support Team Director

    Hi guys, I see the Authorize button in the Host project's Swagger UI.


    For your existing project you need to replace Swashbuckle package with Abp Swashbuckle.

    Then use UseAbpSwaggerUI instead of ~~UseSwaggerUI~~ in your HttpApiHostModule.cs

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    We have enabled swagger login for HostWithIds project: https://github.com/abpframework/abp/pull/6818

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38