2

我已经使用 NSwag 在我的 ASP.NET 项目中设置了 Swagger,它工作正常,但我正在尝试添加对身份验证的支持。

我的身份验证模型是一个简单的用户名/密码,使用OAuthusingApplicationOAuthProvider

我用来登录的网址如下

/令牌

使用 POST 参数:

grant_type=密码&用户名=${用户名}&密码=${密码}

现在我 [in Global.asax] 的招摇设置是

app.UseSwaggerUi(typeof(Global).Assembly, new SwaggerUiSettings
{
    MiddlewareBasePath = "/swagger",
    OAuth2Client = new OAuth2ClientSettings
    {
        ClientId = "my_auth_id",
        //ClientSecret = "bar",
        AppName = "my",
        //Realm = "my_realm",
        //AdditionalQueryStringParameters = { { "foo", "bar" } }
    },
    DocumentProcessors =    {
        new SecurityDefinitionAppender("oauth2", new SwaggerSecurityScheme
        {
            Type = SwaggerSecuritySchemeType.Basic,
            Description = "Description is set htere",
            Flow = SwaggerOAuth2Flow.Password,
            AuthorizationUrl = "https://localhost:28866/token?",
            TokenUrl = "https://localhost:28866/token",
            In = SwaggerSecurityApiKeyLocation.Query
            //Scopes = new Dictionary<string,string>
            //{
            //    //{ "read", "Read access to protected resources" },
            //    { "write", "Write access to protected resources" }
            //}
        })
    },
    OperationProcessors =
    {
        new OperationSecurityScopeProcessor("oauth2")
    }
});

我知道这有点混乱,但我确实在尝试所有可能的选择来让它发挥作用。

所以这实际上给了我授权按钮和用户名和密码字段。但是当我单击登录时,它会刷新 swagger.json 但实际上并没有尝试在任何地方登录?

4

0 回答 0