语言

RequiredScopeAttribute 类

定义

此属性用于控制器、页面或控制器操作来声明 Web API 所需的范围(并验证)。 可以通过两种方式声明这些范围:硬编码它们,或在配置中声明它们。 根据你的选择,使用一个或另一个构造函数。 有关详细信息,请参阅 https://aka.ms/ms-id-web/required-scope-attribute。

[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method)]
public class RequiredScopeAttribute : Attribute, Microsoft.Identity.Web.IAuthRequiredScopeMetadata
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method)>]
type RequiredScopeAttribute = class
    inherit Attribute
    interface IAuthRequiredScopeMetadata
Public Class RequiredScopeAttribute
Inherits Attribute
Implements IAuthRequiredScopeMetadata
继承
RequiredScopeAttribute
属性
实现

构造函数

名称 说明
RequiredScopeAttribute()

默认构造函数。

RequiredScopeAttribute(String[])

验证是否使用正确的作用域调用 Web API。 如果为此 API 获取的令牌代表经过身份验证的用户在其范围声明中没有任何这些 acceptedScopes 令牌,该方法将更新 HTTP 响应,提供状态代码 403(禁止访问),并向响应正文写入一条消息,告知令牌中预期哪些范围。

属性

名称 说明
AcceptedScope

此 Web API 接受的范围。

IsReusable

未使用:与授权筛选器的接口兼容性。

RequiredScopesConfigurationKey

包含所需作用域(用空格分隔)的配置密钥的完全限定名称。

适用于