OAuth 2.0授权框架中文版 [8] - 扩展点

8. 扩展点 - Extensibility

8.1 定义访问令牌类型 - Defining Access Token Types

访问令牌类型可以以如下两种方式定义:

  • 注册到访问令牌类型注册表(按照章节11.1中的流程);
  • 使用代表其名称的绝对路径URI;

Access token types can be defined in one of two ways: registered in
the Access Token Types registry (following the procedures in
Section 11.1), or by using a unique absolute URI as its name.

使用URI名称的令牌类型,应限制为特定的供应商的实现,这些实现通常是不通用的,且仅特定于使用它们的资源服务器。

Types utilizing a URI name SHOULD be limited to vendor-specific
implementations that are not commonly applicable, and are specific to
the implementation details of the resource server where they are
used.

其余的令牌类型都应该注册到注册表。类型名称必须遵循type-name范式,如果该类型定义包含HTTP认证方案,则类型名称必须与HTTP认证方案相同(如[RFC2617]所定义),"example"这种类型作为示例中的保留类型。

type-name  = 1*name-char
name-char  = "-" / "." / "_" / DIGIT / ALPHA

All other types MUST be registered. Type names MUST conform to the
type-name ABNF. If the type definition includes a new HTTP
authentication scheme, the type name SHOULD be identical to the HTTP
authentication scheme name (as defined by [RFC2617]). The token type
“example” is reserved for use in examples.

 type-name  = 1*name-char
 name-char  = "-" / "." / "_" / DIGIT / ALPHA

8.2 定义新的端点的参数 - Defining New Endpoint Parameters

在授权或令牌端点使用新的请求或响应参数,需要遵循章节11.2中的流程,在OAuth Parameters注册表中定义和注册。

New request or response parameters for use with the authorization
endpoint or the token endpoint are defined and registered in the
OAuth Parameters registry following the procedure in Section 11.2.

参数名必须遵循param-name范式,并且参数值的语法也需要被明确定义(比如,使用ABNF,或者指向已存在参数的语法的引用)。

Parameter names MUST conform to the param-name ABNF, and parameter
values syntax MUST be well-defined (e.g., using ABNF, or a reference
to the syntax of an existing parameter).

 param-name  = 1*name-char
 name-char   = "-" / "." / "_" / DIGIT / ALPHA

未注册的、限制于供应商的参数扩展通常不具备适用性,并且受限于使用他们的授权服务器。这些参数通常可以加多一个命名前缀,以避免与其它注册值冲突(比如,使用’companyname_'前缀)。

Unregistered vendor-specific parameter extensions that are not
commonly applicable and that are specific to the implementation
details of the authorization server where they are used SHOULD
utilize a vendor-specific prefix that is not likely to conflict with
other registered values (e.g., begin with ‘companyname_’).

8.3 定义新的授权流程 - Defining New Authorization Grant Types

可以通过为grant_type参数指定唯一的绝对URI路径,来定义新的授权流程。如果这个扩展的授权类型需要在令牌端点使用额外的参数,那必须如章节11.2所述,在OAuth Parameters注册表中进行注册。

New authorization grant types can be defined by assigning them a
unique absolute URI for use with the “grant_type” parameter. If the
extension grant type requires additional token endpoint parameters,
they MUST be registered in the OAuth Parameters registry as described
by Section 11.2.

8.4 定义授权端点的响应类型 - Defining New Authorization Endpoint Response Types

新的响应类型可参考章节11.3中的流程,注册到Authorization Endpoint Response Types注册表中。响应类型名称比如遵循如下范式:

response-type  = response-name *( SP response-name )
response-name  = 1*response-char
response-char  = "_" / DIGIT / ALPHA

New response types for use with the authorization endpoint are
defined and registered in the Authorization Endpoint Response Types
registry following the procedure in Section 11.3. Response type
names MUST conform to the response-type ABNF.

response-type  = response-name *( SP response-name )
response-name  = 1*response-char
response-char  = "_" / DIGIT / ALPHA

如果响应类型中包含一个或多个空格,则将其看待为空格分割的响应类型的列表,且顺序无关。多个响应类型的集合按照一种顺序进行注册即可,其它的组合顺序也可以达到相同的效果。

If a response type contains one or more space characters (%x20), it
is compared as a space-delimited list of values in which the order of
values does not matter. Only one order of values can be registered,
which covers all other arrangements of the same set of values.

比如,响应类型"token code"在本规范中并未定义,因此可以将其定义为扩展的响应类型,一旦注册,那与其顺序不同的"code token"就不能再注册为新的响应类型,但这两个顺序不同的值都可以同时用来表明同一种响应类型。

For example, the response type “token code” is left undefined by this
specification. However, an extension can define and register the
“token code” response type. Once registered, the same combination
cannot be registered as “code token”, but both values can be used to
denote the same response type.

8.5 Defining Additional Error Codes - 定义额外的错误码

当进行协议扩展时(访问令牌类型扩展、参数扩展以及授权类型扩展等),如果需要额外的错误码与授权码流程错误码、隐式授权模式错误码、令牌错误响应以及资源访问错误响应等配合使用,那这些额外的错误码需要进行定义。

In cases where protocol extensions (i.e., access token types,
extension parameters, or extension grant types) require additional
error codes to be used with the authorization code grant error
response (Section 4.1.2.1), the implicit grant error response
(Section 4.2.2.1), the token error response (Section 5.2), or the
resource access error response (Section 7.2), such error codes MAY be
defined.

如果扩展的错误码需要与已注册的令牌类型、已注册的端点参数或者一个扩展的授权类型一起使用,那该错误码必须进行注册(遵循章节11.4)。如果与未注册的扩展点配合使用,则可注册也可不注册。

Extension error codes MUST be registered (following the procedures in
Section 11.4) if the extension they are used in conjunction with is a
registered access token type, a registered endpoint parameter, or an
extension grant type. Error codes used with unregistered extensions
MAY be registered.

错误码必须遵循如下ABNF的范式,如果可能,那在该范式前再增加一个标识前缀。比如,为"example"这个扩展参数增加的标识其无效的扩展错误码,则可以命名为"example_invalid"。

error      = 1*error-char
error-char = %x20-21 / %x23-5B / %x5D-7E

Error codes MUST conform to the error ABNF and SHOULD be prefixed by
an identifying name when possible. For example, an error identifying
an invalid value set to the extension parameter “example” SHOULD be
named “example_invalid”.

 error      = 1*error-char
 error-char = %x20-21 / %x23-5B / %x5D-7E
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 前后端分离是一种将前端界面与后端逻辑进行分离开发的架构方式,使得前端与后端可以并行开发。OAuth 2.0是一种授权框架,用于授权和认证流程的规范化,而Spring Security是一个在Java中实现安全控制的框架,提供了大量的安全特性。Spring Authorization Server是Spring Security中用于实现授权服务器的模块,它支持OAuth 2.0的各种授权模式。 密码模式是OAuth 2.0中的一种授权模式,它允许用户通过提交用户名和密码来获取访问令牌,然后使用该令牌来访问受保护的资源。在前后端分离的架构中,可以使用Spring Security配合Spring Authorization Server来实现密码模式的认证和授权。 在密码模式下,前端首先需要收集用户的用户名和密码,并将其发送给后端。后端使用Spring Security提供的密码编码器对密码进行加密,并验证用户名和密码的正确性。如果验证通过,则后端向客户端颁发一个访问令牌,通常是一个JWT(JSON Web Token)。前端使用获得的访问令牌来访问需要受保护的资源,每次请求将该令牌作为Authorization头的Bearer字段发送给后端进行验证。后端可以使用Spring Security的资源服务器来验证该令牌的有效性,并根据用户的权限控制对资源的访问。 使用Spring Security和Spring Authorization Server的密码模式可以实现安全的前后端分离架构。通过合理配置和使用安全特性,可以保障用户的身份认证和资源的授权,确保系统的安全性。 ### 回答2: 前后端分离是一种软件架构模式,前端和后端通过使用API进行通信,分别负责处理用户界面和数据逻辑。OAuth 2.0是一种用于授权的开标准协议,它允许用户在第三方应用程序中授权访问其受保护的资源。Spring Security是Spring框架中的一个模块,提供了身份验证和授权功能。 在前后端分离的架构中,前端应用程序通常需要使用OAuth 2.0协议进行用户授权,以访问后端应用程序的受保护资源。为了实现密码模式,我们可以使用Spring Security的模块之一,即spring-authorization-server。 spring-authorization-server是Spring Security的一个子模块,用于实现OAuth 2.0协议中的授权服务器。密码模式是OAuth 2.0协议中的一种授权模式,允许前端应用程序通过用户的用户名和密码进行授权。密码模式在安全性上有一定的风险,因此在实际应用中需要谨慎使用。 使用spring-authorization-server的密码模式,我们可以在前端应用程序中收集用户的用户名和密码,并将其提交给后端应用程序进行验证。后端应用程序将使用Spring Security进行身份验证,并向前端应用程序颁发一个访问令牌,该令牌可以用于后续的API请求。 通过使用前后端分离、OAuth 2.0和spring-authorization-server的密码模式,我们可以实现安全的用户授权和身份验证机制,确保只有经过授权的用户才能访问受保护的资源。这种架构模式能够提高系统的安全性和可扩展性,适用于各种类型的应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值