Asp.net web api2 网络API 2,招摇过市&;标识服务器3

Asp.net web api2 网络API 2,招摇过市&;标识服务器3,asp.net-web-api2,swagger,swagger-ui,identityserver3,Asp.net Web Api2,Swagger,Swagger Ui,Identityserver3,我正在尝试使用Swagger和IdentityServer设置一个Web API,但我不知道如何使Swagger正常工作 我的React应用程序正在使用IdentityServer,我设法使ui正常工作,但当我尝试激活身份验证时,总是出现“作用域不足”错误 这是我的配置: 客户 公共静态IEnumerable Get() { 返回新的[] { 新客户 { ClientId=“ipassportimplicit”, ClientName=“iPassport(隐式)”, 流=流。隐式, Allow

我正在尝试使用Swagger和IdentityServer设置一个Web API,但我不知道如何使Swagger正常工作

我的React应用程序正在使用IdentityServer,我设法使ui正常工作,但当我尝试激活身份验证时,总是出现“作用域不足”错误

这是我的配置:

客户
公共静态IEnumerable Get()
{
返回新的[]
{
新客户
{
ClientId=“ipassportimplicit”,
ClientName=“iPassport(隐式)”,
流=流。隐式,
AllowAccessToAllScopes=true,
//redirect=React应用程序回调页面的URI
重定向URI=新列表
{
Constants.iPassportReact+“callback.html”
}
},
新客户
{
ClientId=“swaggerui”,
ClientName=“炫耀(隐式)”,
流=流。隐式,
AllowAccessTokensViaBrowser=true,
PostLogoutRedirectUris=新列表
{
"http://localhost:53633/swagger/"
},
AllowAccessToAllScopes=true,
重定向URI=新列表
{
"http://localhost:53633/swagger/ui/o2c-html“
}
}
};
}
范围
公共静态IEnumerable Get()
{
返回新列表
{                    
新范围
{ 
Name=“passportmanagement”,
DisplayName=“护照管理”,
Description=“允许应用程序代表您管理护照。”,
Type=ScopeType.Resource
},
新范围
{
Name=“招摇过市”,
DisplayName=“招摇过市用户界面”,
Description=“显示招摇界面”,
Type=ScopeType.Resource
}
};
}
昂首阔步
公共静态无效寄存器(HttpConfiguration配置)
{
var thissassembly=typeof(SwaggerConfig).Assembly;
配置
.EnableSwagger(c=>
{
c、 单一api版本(“v2”、“api_iPassport”);
c、 OAuth2(“OAuth2”)
.说明(“OAuth2隐式授权”)
.Flow(“隐式”)
.AuthorizationUrl(常数.ipassportsAuthorizationEndpoint)
.TokenUrl(常量.ipassportststokendpoint)
.Scopes(Scopes=>
{
添加(“招摇过市”、“招摇过市用户界面”);
});
c、 操作过滤器();
})
.EnableSwaggerUi(c=>
{   
c、 EnableOAuth2Support(“招摇过市用户界面”、“招摇过市领域”、“招摇过市用户界面”);
});
}
操作过滤器
公共类分配OAuth2安全要求:IOperationFilter
{
public void Apply(操作,SchemaRegistry SchemaRegistry,apisdescription apisdescription)
{
var actFilters=apiscription.ActionDescriptor.GetFilterPipeline();
var allowsAnonymous=actFilters.Select(f=>f.Instance).OfType().Any();
如果(允许匿名)
return;//必须是匿名方法
//var scopes=apiscription.ActionDescriptor.GetFilterPipeline()
//.Select(filterInfo=>filterInfo.Instance)
//第()类
//.SelectMany(attr=>attr.Roles.Split(','))
//.Distinct();
if(operation.security==null)
operation.security=新列表();
var oAuthRequirements=新字典
{
{“oauth2”,新列表{“招摇过市”}
};
operation.security.Add(oAuthRequirements);
}
}
响应头 有什么我看不见的吗?感谢大家的帮助


谢谢

我的问题是在Web API的Startup.cs类中,我没有将所需的作用域添加到

public void ConfigureAuth(IAppBuilder应用程序)
{
var options=new IdentityServerBearerTokenAuthenticationOptions()
{
Authority=Constants.iPassportSTS,
RequiredScopes=new[]{“passportmanagement”,“swagger”}
};
app.useIdentityServerBearnerTokenauthentication(选项);
}

我的问题是在Web API的Startup.cs类中,我没有将所需的作用域添加到

public void ConfigureAuth(IAppBuilder应用程序)
{
var options=new IdentityServerBearerTokenAuthenticationOptions()
{
Authority=Constants.iPassportSTS,
RequiredScopes=new[]{“passportmanagement”,“swagger”}
};
app.useIdentityServerBearnerTokenauthentication(选项);
}
{
  "date": "Fri, 12 May 2017 03:37:08 GMT",
  "www-authenticate": "Bearer error=\"insufficient_scope\"",
  "x-sourcefiles": "=?UTF-8?B?TzpcTG9jYWwgV29ya3NwYWNlXFZTVFMgSUJNXFJlcG9zXFdlYkFQSVxhcGlfaVBhc3Nwb3J0XGFwaV9pUGFzc3BvcnRcYXBpXFVzZXJcR2V0?=",
  "server": "Microsoft-IIS/10.0",
  "x-powered-by": "ASP.NET",
  "content-length": "0",
  "content-type": null
}