且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何做到应用程序(服务器到服务器)认证,OAuth 2.0用户,网络API 2.0

更新时间:2023-02-07 21:54:29

的OAuth有不同的补助的类型,你需要的是客户端证书批准的应用程序本身。这是您将看到谷歌/ Facebook的的有所不同,因为没有重定向/浏览器交互。

OAuth has different grant types, the one you need is "client credentials" to authorize the application itself. This is different from the ones you see for google/facebook, since there is no redirect/browser interaction.

POST https://oauthEndpointurl/token?grant_type=client_credentials&client_id=CLIENT_ID&client_secret=CLIENT_SECRET

客户端ID和客户端密钥发送到服务器,然后返回令牌,并可能刷新令牌,具体取决于你的实现。

Client ID and Client Secret is sent to the server and then the token is returned and possibly a refresh token depending on you're implementation.

然后你所有你需要做的就是发回的令牌在请求的报头。 (如果你使用一个库,然后它已经处理的。)

Then you all you need to do is send the token back in the header of the request. (if you're using a library then it's handled already.)

"Authorization: Bearer xxxxTOKENxxxxx"

结帐这篇文章上做的更多详细信息:

Checkout this article on DO for more details:

https://www.digitalocean.com/community/教程/一介绍到OAuth的2