[英]Simple OAuth2 authentication - Request an access token
I have been struggling with this now for a while. 我已经为此努力了一段时间。 So if someone could help me it would be great.
因此,如果有人可以帮助我,那就太好了。
I am trying to get a simple access token from the TwitchTV API. 我正在尝试从TwitchTV API获取一个简单的访问令牌。 I am referring to this link: https://dev.twitch.tv/docs/authentication/#getting-tokens
我指的是此链接: https : //dev.twitch.tv/docs/authentication/#getting-tokens
GET https://id.twitch.tv/oauth2/authorize
?client_id=<your client ID>
&redirect_uri=<your registered redirect URI>
&response_type=<type>
&scope =<space-separated list of scopes>
So thats where I begin to struggle already. 所以那就是我已经开始挣扎的地方。 How exactly do I make such requests in an ASP.NET MVC application?
如何在ASP.NET MVC应用程序中发出这样的请求? I see that I have an Startup.Auth.cs class where I can configure OAuth Authentications.
我看到我有一个Startup.Auth.cs类,可以在其中配置OAuth身份验证。 But how does such authentication have to look like?
但是这种身份验证必须看起来如何?
It then says in the documentation: 然后在文档中说:
If the user authorizes your application, the user is sent to your redirect URI, with an ID token and optionally an access token (if that was requested):
如果用户授权了您的应用程序,则会将该用户发送到您的重定向URI,其中包含ID令牌和可选的访问令牌(如果已请求):
https://<your registered redirect URI>#id_token=<an id
token>&access_token=<an access token>
Now how do I access this token? 现在如何访问此令牌? Can someone please give me a small Code example of how I should start with this API?
有人可以给我一个小代码示例,说明如何使用此API吗? I really dont have any experience with such technology.
我真的没有这种技术的任何经验。 How do I have to configure my
Startup.Auth.cs
and how does my Action have to look like, that starts the authentication? 我必须如何配置
Startup.Auth.cs
以及我的“动作”外观如何才能启动身份验证?
Please refer to the link above in your answer. 请在您的答案中参考上面的链接。 Thank you!
谢谢!
You can create a redirect URI as callback URL. 您可以将重定向URI创建为回调URL。 when a user logged in in your app the callback will be triggered containing the Access Token and other information.
当用户登录您的应用程序时,将触发包含访问令牌和其他信息的回调。
here is the sample snippet in PHP ( https://yourhost.com/outhcallback.php ) 这是PHP中的示例代码段( https://yourhost.com/outhcallback.php )
<?php
$acccesstoken=$_REQUEST["access_token"];
$id_token=$_REQUEST["id_token"];
store_to_session(accesstoken);
?>
now you have the token. 现在您有了令牌。 if this token you require in server-side store to the session and if require in client-side store to local storage.
如果需要此令牌,则需要在服务器端存储中添加到会话,如果需要,则需要在客户端存储中添加到本地存储。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.