关于node.js:OAuth 2.0 Flow工作原理node-oauth2-server

OAuth 2.0 Flow how it works node-oauth2-server

使用https://github.com/thomseddon/node-oauth2-server在NodeJS中实现OAuth Server时

我正在尝试了解OAuth 2.0的流程

我以某种方式成功实现了npm软件包,但是我怀疑,出了点问题。

我会解释我如何成功。

第一个请求:

1
2
3
4
5
6
POST: http://localhost:3000/oauth/token
grant_type=password
client_id=1011
client_secret=somesecret
username=admin
password=admin

第一个回应:

1
2
3
4
5
6
{
token_type:"bearer"
access_token:"7f5261011fb0f84a4e193889fff4b7478f2a4cb2"
expires_in: 3600
refresh_token:"da83de41966979ced65b3841e1758335a811c0c2"
}

获取访问令牌后,我将发送另一个http呼叫

第二个请求:

1
2
GET http://localhost:3000/secret
Authorization: Bearer 7f5261011fb0f84a4e193889fff4b7478f2a4cb2

第二响应:

1
{"data":"Secret area accessible"}

但是在这里我完全困惑

问题1. Authorization_code部分丢失

问题2.在第一个呼叫中,我需要发送client_secret和user_password-如果同时发送这两个消息,则意味着oauth客户端正在向用户(浏览器)公开机密,或者用户正在向OAuth客户端提供密码。

如果整个OAuth 2.0的请求/响应模式如下所示,请与我分享

1
2
3
4
5
6
7
a. browser -> oauth server POST /oauth/authorize?client_id,username,password
b. USER GRANTS PERMISSION
c. browser -> oauth server RESPONSE auth_code
d. browser -> oauth client POST auth_code
e. oauth_client -> oauth server POST auth_code
e. oauth server -> oauth_client  RESPONSE access_token
f. oauth_client  -> resource_server POST /resource?access_token (Question 3. But here how resource server validates access token is valid or not )

OAuth 2.0定义了几种通过所谓的"授予"获得访问令牌的方式。 您的请求表明您当前正在使用"资源所有者密码凭据"授予,请参阅:https://tools.ietf.org/html/rfc6749#section-1.3.3。 该授权确实使用户名/密码暴露给客户端,这就是为什么它违反了OAuth 2.0的大多数目的并且仅用于迁移的原因,请参见:https://tools.ietf.org/html/rfc6749#section-10.7

授权码授权是一种单独的授权类型,通过该授权类型,用户可以通过浏览器重定向到授权端点,从而使客户端不参与用户验证过程。 您似乎在a.-f.中描述的流程中提到了这一点。 由于这是一种不同的授予类型,因此您不会在资源所有者密码凭证授予中看到"授权代码"。

在正确的授权码授予流程中, 将是重定向而不是POST,例如:a. browser -> oauth server Redirect /oauth/authorize?client_id,response_type=code