简体   繁体   English

简单的OAuth2身份验证-请求访问令牌

[英]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.

相关问题 带有刷新令牌的协调API OAuth2身份验证 - Coordinate API OAuth2 authentication with refresh token Azure AD OAuth2访问令牌请求错误-400错误的请求 - Azure AD OAuth2 Access Token Request Error - 400 Bad Request Google OAuth2服务帐户访问令牌请求会提供“无效请求”响应 - Google OAuth2 Service Account Access Token Request gives 'Invalid Request' Response WinRT-OAuth2获取访问令牌 - WinRT - OAuth2 get access token 控制台应用程序中的 OAuth2 访问令牌 - OAuth2 Access token in console application 从CefSharp获取OAuth2访问令牌 - Get OAuth2 access token from CefSharp 请求的身份验证凭据无效。 预期的 OAuth 2 访问令牌、登录 cookie 或其他有效的身份验证凭据 - Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential 无法从Google OAuth2令牌端点获取访问令牌 - Unable to get access token from Google OAuth2 Token endpoint LInkedIn oAuth2请求令牌400错误请求 - LInkedIn oAuth2 request token 400 Bad Request Azure 功能根 URL 使用不记名令牌/OAuth2 进行身份验证 - Azure Functions root URL authentication with bearer token/OAuth2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM