2016-07-07 78 views
0

我正在使用swashbuckle将swagger添加到我的asp.net mvc web api项目中。我看到了添加OAuth2的选项,但我的网站需要安装。我如何要求身份验证以wsfederation查看swagger ui?在SwaggerConfig文件我应该如何将身份验证添加到swashbuckle?

GlobalConfiguration.Configuration 
    .EnableSwagger(c => 
    { 
     c.SingleApiVersion("v1", "Services"); 
    }) 
    .EnableSwaggerUi(c => { }); 

回答

1

认证是直接关系到记录您的API,而不是实际执行中,可以这么说。 所以,如果你使用你的swaggerConfig如下:

c.OAuth2("oauth2") 
       .Description("OAuth2 Implicit Grant") 
       .Flow("implicit") 
       .AuthorizationUrl("http://petstore.swagger.io/oauth/dialog") 
       .Scopes(scopes => 
       { 
        scopes.Add("read:pets", "read your pets"); 
        scopes.Add("write:pets", "modify pets in your account"); 
       }); 

这将产生在招摇JSON文件中的以下securitydefinition

securityDefinitions: 
    petstore_auth: 
    type: oauth2 
    authorizationUrl: 'http://petstore.swagger.io/oauth/dialog' 
    flow: implicit 
    scopes: 
     'write:pets': modify pets in your account 
     'read:pets': read your pets 

要回答

我怎么能要求身份验证用 wsfederation查看swagger ui?

只需添加全球认证的WebApiConfig.cs文件,类似于以下(如果您正在使用的MessageHandler或过滤器)

config.Filters.Add(new WSFederationAuthentication()); 

查看招摇文档直接的WebAPI相关的东西。

虽然您可能会遇到一些问题,因为Swagger获得了文档客户端。

相关问题