Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to allow API call from Swagger? #4140


User avatar
0
manojreddy created

I'm using [AbpAuthorize] with methods, so I'm not able to call methods from Swagger API. The reason is simple that user is not logged in, so Do we have any way to send login credentials from Swagger UI?

Or Do we have any way to have configurable [AbpAuthorize] based on some flag? So that for my development environment I can disable [AbpAuthorize] and in the live environment, I will enable [AbpAuthorize].


5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ManojReddy,

    We haven't integrated it into AspNet Zero but you can use <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero-core-template/pull/108">https://github.com/aspnetboilerplate/mo ... e/pull/108</a>.

  • User Avatar
    0
    manojreddy created

    Thanks for your reply, it works perfectly.

    I'm not able to get the key (allowSwaggerToRunAPIs ) value from the app.config file in Startup.cs file. I want to make this as configurable.

    <configuration>
      <appSettings>
        <add key="owin:AutomaticAppStartup" value="false"/>
        <add key="allowSwaggerToRunAPIs" value="true"/>
      </appSettings>
      <runtime>
          <gcServer enabled="true"/>
       </runtime>
    </configuration>
    
  • User Avatar
    0
    aaron created
    Support Team

    Put that in appsettings.json:

    "App": {
      "AllowSwaggerToRunAPIs": "true"
    }
    

    And get it in Startup.cs:

    if (bool.Parse(_appConfiguration["App:AllowSwaggerToRunAPIs"])) {
        // ...
    }
    
  • User Avatar
    0
    manojreddy created

    Link appsettings.json is giving 404. [https://github.com/aspnetzero/aspnet-zero-core/blob/67b8cdd1542e2cdfef982b08a886df2f6c7c1e56/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Host/appsettings.json#L13])

  • User Avatar
    0
    aaron created
    Support Team

    You need to login with your GitHub account to access the private repo. You can invite yourself here: <a class="postlink" href="https://aspnetzero.com/LicenseManagement">https://aspnetzero.com/LicenseManagement</a>