简体   繁体   English

使用 node js 取回 Twitch API 的访问令牌

[英]Get back Access Token of Twitch API with node js

I am developping a google chrome extension in which I need to authenticate the user on Twitch.我正在开发一个 google chrome 扩展,我需要在其中对 Twitch 上的用户进行身份验证。 According to https://github.com/justintv/Twitch-API/blob/master/authentication.md , I registered an application to get a client_id and my chrome extension open the following link:根据https://github.com/justintv/Twitch-API/blob/master/authentication.md ,我注册了一个应用程序来获取 client_id 并且我的 chrome 扩展打开以下链接:

https://api.twitch.tv/kraken/oauth2/authorize
    ?response_type=token
    &client_id=[your client ID]
    &redirect_uri=[your registered redirect URI]
    &scope=[space separated list of scopes]

After accepting to use my application, users are redirected to this link:接受使用我的应用程序后,用户将被重定向到此链接:

https://[your registered redirect URI]/#access_token=[an access token]&scope=[authorized scopes]

[your registered redirect URI] is the link of my node js server. [您注册的重定向 URI] 是我的节点 js 服务器的链接。 I need to save the access_token information, but I don't know how to access to elements after '#'.我需要保存access_token信息,但是我不知道如何访问'#'之后的元素。 The request url or its params aren't containing them.请求 url 或其参数不包含它们。

There is already an explanation in the documentation just below the line that you 've posted:在您发布的行下方的文档中已经有说明:

Note that the access token is in the URL fragment, not the query string, so it won't show up in HTTP requests to your server.请注意,访问令牌位于 URL 片段中,而不是查询字符串中,因此它不会出现在对您的服务器的 HTTP 请求中。 URL fragments can be accessed from JavaScript with document.location.hash可以使用 document.location.hash 从 JavaScript 访问 URL 片段

The browser/client removes the fragment elements before sending the request to the server.浏览器/客户端在向服务器发送请求之前删除片段元素。 You have to load the page, have a small javascript script and retrieve the values from the client.您必须加载页面,使用一个小的 javascript 脚本并从客户端检索值。 Then you can decide how to handle the data.然后您可以决定如何处理数据。 For example, you can fire an ajax request to your server.例如,您可以向服务器发出 ajax 请求。

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

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