我'm trying to perform user authentication via OAuth 2.0 for a UWP C# Inoreader app I'正在努力 . 有关步骤的文档可在此处找到:https://www.inoreader.com/developers/oauth .
我不知道如何编写这部分代码:
获取访问权限和刷新令牌获取AUTHORIZATION_CODE并通过向以下地址发送POST请求立即交换它以进行访问和刷新令牌:https://www.inoreader.com/oauth2/token请求:POST / oauth2 / token HTTP / 1.1主持人:www.inoreader.com内容长度:217内容类型:application / x-www-form-urlencoded用户代理:你的用户代理代码= [AUTHORIZATION_CODE]&redirect_uri = [REDIRECT_URI]&client_id = [CLIENT_ID] &client_secret = [CLIENT_SECRET]&scope =&grant_type = authorization_code请不要忘记包含Content-type标头!
也就是说,使用自定义标头发送POST请求以及传递属性值 .
2 回答
要在UWP中执行OAuth 2.0身份验证操作,我们通常会利用WebAuthenticationBroker Class .
有关详细信息,请参阅Web authentication broker .
以下是使用WebAuthenticationBroker class和Windows.Web.Http.HttpClient class的示例 .
WebAuthenticationBroker
类用于“ Consent page redirection ”,Windows.Web.Http.HttpClient
类用于“ Obtaining access and refresh tokens ” .使用HttpFormUrlEncodedContent时,它应该能够自动将
Content-type
标头设置为application/x-www-form-urlencoded
.要获取令牌,请检查此链接https://codeserendipity.com/2017/07/12/oauth2-get-an-access-token-c/
要使用令牌,请查看以下答案:How can I use the access token to get a list of projects from a website in c#?