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
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

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

    Hi,

    You can open /account/login page to login.

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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
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.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.