c# - 使用 ASP.NET Core 设置 Twitter 外部登录时出错
问题描述
我有一个 ASP.Net Core 2.2 应用程序,并且 twitter 授权已开始显示Response status code does not indicate success: 403 (Forbidden)
错误。我已经三次检查了 ClientId、ClientSecret 以及网站 url、回调 url、条款和条件 url、隐私政策 url,一切似乎都很好(请参见下面的屏幕截图)。关于我的下一步应该是什么的任何输入?
这里的文档说"The request is understood, but it has been refused or access is not allowed. An accompanying error message will explain why. This code is used when requests are being denied due to update limits . Other reasons for this status being returned are listed alongside the error codes in the table below."
。
当 ASP.Net Core twitter 身份验证与 Twitter 通信时,如何捕获错误代码(以及 HTTP 状态代码(在本例中为 403))?
启动.cs
public void ConfigureServices(IServiceCollection services)
{
#region Add Twitter Authentication
.AddTwitter(twitterOptions =>
{
twitterOptions.ConsumerKey = Configuration["TwitterAuthSettings:ClientId"];
twitterOptions.ConsumerSecret = Configuration["TwitterAuthSettings:ClientSecret"];
twitterOptions.SaveTokens = true;
twitterOptions.Events.OnCreatingTicket = oAuthCreatingTicketContext =>
{
var authenticationTokens = oAuthCreatingTicketContext.Properties.GetTokens().ToList();
var authenticationToken = new AuthenticationToken()
{
Name = "TicketCreated",
Value = DateTime.UtcNow.ToString()
};
authenticationTokens.Add(authenticationToken);
oAuthCreatingTicketContext.Properties.StoreTokens(authenticationTokens);
return Task.CompletedTask;
};
twitterOptions.Events.OnTicketReceived = ticketReceivedContext =>
{
return Task.CompletedTask;
};
twitterOptions.Events.OnRemoteFailure = remoteFailureContext =>
{
return Task.CompletedTask;
};
})
#endregion Add Twitter Authentication
}
堆栈跟踪:
Exception occured: System.Net.Http.HttpRequestException: Response status code does not indicate success: 403 (Forbidden).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() at Scrubber.ExceptionMiddleware.InvokeAsync(HttpContext httpContext) in /src/Scrubber/ExceptionMiddleware.cs:line 25
解决方案
推荐阅读
- vue.js - 如何在 V-select 中添加条件?
- delphi - 64 位平台上 Delphi 中的 CryptProtectData
- java - 如何从 Map 获取两个键/值对到 TextView
- python - 调用另一个函数后重新启动一个函数
- c++ - 为什么从 WAV 文件中读取的 SubChunk2Size 值等于 3452816845?
- javascript - Puppeteer 协议错误(Runtime.callFunctionOn):目标关闭
- c# - 在 ASP.NET MVC 中上传和显示图像
- c++ - 我们的程序能否在编译时确定它在哪个编译器中编译?
- android - Espresso 意式负检查
- c++ - 为什么link_libraries(stdc++fs) 可以工作,但-lstdc++fs 不行?