简体   繁体   English

Github API OAuth 令牌验证

[英]Github API OAuth token validation

Is there any way to validate my OAuth token for the github API?有什么方法可以验证我的 github API 的 OAuth 令牌吗? By 'token' I mean the one I get after the user has logged in to my website. “令牌”是指用户登录我的网站后得到的令牌。 I store it on the client computer using cookies, but just checking if there is a token is not enough: I need to actually check if the token is valid or not.我使用 cookie 将它存储在客户端计算机上,但仅检查是否有令牌是不够的:我需要实际检查令牌是否有效。 Currently this requires me to make a request for information and then catching the errors.目前,这需要我请求信息,然后捕获错误。 However, this is really damaging my rates and also my load speed as the github API is sloooow ... I am using Node.js, express and the octonode library.然而,这确实损害了我的费率和我的加载速度,因为 github API太慢了……我正在使用 Node.js、express 和octonode库。

I tried looking at the github API docs, but they are minimal and slightly suckish.我尝试查看 github API 文档,但它们很小而且有点糟糕。 Maybe this is to do with OAuth, I'm not sure.也许这与 OAuth 有关,我不确定。

Thanks in advance.提前致谢。

From the Github API docs on authorizations :来自Github API 文档的授权

OAuth applications can use a special API method for checking OAuth token validity without running afoul of normal rate limits for failed login attempts. OAuth 应用程序可以使用特殊的 API 方法来检查 OAuth 令牌的有效性,而不会违反登录尝试失败的正常速率限制。

Authentication works differently with this particular endpoint.身份验证与此特定端点的工作方式不同。 You must use Basic Authentication when accessing it, where the username is the OAuth application client_id and the password is its client_secret.访问时必须使用基本身份验证,其中用户名是 OAuth 应用程序 client_id,密码是其 client_secret。 Invalid tokens will return 404 NOT FOUND.无效的令牌将返回 404 NOT FOUND。

You can do this with curl:你可以用 curl 做到这一点:

curl -u client_id:client_secret https://api.github.com/applications/:client_id/tokens/:token

Or, if using fetch, use Curl to Fetch .或者,如果使用 fetch,请使用Curl 来 Fetch

This is compiled from the helpful comments on the OP's question.这是根据对 OP 问题的有用评论汇编而成的。

Check headers to see what OAuth scopes you have, and what the API action accepts:检查标头以了解您拥有哪些 OAuth 范围,以及 API 操作接受哪些内容:

curl -H "Authorization: token OAUTH-TOKEN" https://api.github.com/users/codertocat -I
HTTP/1.1 200 OK
X-OAuth-Scopes: repo, user
X-Accepted-OAuth-Scopes: user
curl -H "Authorization: <TOKEN>" https://api.github.com/

或者

curl https://api.github.com/ -u <USERNAME>:<TOKEN>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM