RequiredScopeAttribute 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
重载
| 名称 | 说明 |
|---|---|
| RequiredScopeAttribute() |
默认构造函数。 |
| RequiredScopeAttribute(String[]) |
验证是否使用正确的作用域调用 Web API。
如果为此 API 获取的令牌代表经过身份验证的用户在其范围声明中没有任何这些 |
RequiredScopeAttribute()
默认构造函数。
public RequiredScopeAttribute();
Public Sub New ()
示例
[RequiredScope(RequiredScopesConfigurationKey="AzureAD:Scope")]
class Controller : BaseController
{
}
适用于
RequiredScopeAttribute(String[])
验证是否使用正确的作用域调用 Web API。
如果为此 API 获取的令牌代表经过身份验证的用户在其范围声明中没有任何这些 acceptedScopes 令牌,该方法将更新 HTTP 响应,提供状态代码 403(禁止访问),并向响应正文写入一条消息,告知令牌中预期哪些范围。
public RequiredScopeAttribute(params string[] acceptedScopes);
new Microsoft.Identity.Web.Resource.RequiredScopeAttribute : string[] -> Microsoft.Identity.Web.Resource.RequiredScopeAttribute
Public Sub New (ParamArray acceptedScopes As String())
参数
- acceptedScopes
- String[]
此 Web API 接受的范围。
示例
在控制器/页面/操作上添加以下属性以保护:
[RequiredScope("access_as_user")]
注解
当范围不匹配时,响应为 403(禁止),因为用户已经过身份验证(因此不是 401),但未获得授权。
另请参阅
- <xref:RequiredScopeAttribute()>