的WebAPI的OAuth UseOAuthBearerAuthentication给出"序列包含多个元素"错误 [英] WebApi OAuth UseOAuthBearerAuthentication gives "Sequence contains more than one element" error
本文介绍了的WebAPI的OAuth UseOAuthBearerAuthentication给出"序列包含多个元素"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我由这些线配置我的WebAPI的OAuth 2.0:
I configured my WebApi OAuth 2.0 by these lines:
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
{
Provider = new OAuthBearerAuthenticationProvider(),
});
app.UseOAuthBearerTokens(OAuthOptions);
但它给了我下面的错误在每个请求:
But it gives me the following error at each request :
Message : An error has occurred.
ExceptionMessage : Sequence contains more than one element
ExceptionType : System.InvalidOperationException
StackTrace : at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at Microsoft.Owin.Security.AuthenticationManager.d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.HostAuthenticationFilter.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.AuthenticationFilterResult.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()
我的 OAuthOptions
是:
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
AuthorizeEndpointPath = new PathString("/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
AllowInsecureHttp = true,
};
}
如果我评论的 UseOAuthBearerAuthentication 一切OK!我没有定制OAuthBearerAuthenticationProvider但我直接使用它,但它为什么给我的错误?
If I comment UseOAuthBearerAuthentication everything is ok! I didn't customize OAuthBearerAuthenticationProvider yet and I use it directly but why does it give me error?
推荐答案
这应该是一个错误!使用
It should be a bug! Use
app.UseOAuthAuthorizationServer(OAuthOptions);
而不是
app.UseOAuthBearerTokens(OAuthOptions);
这篇关于的WebAPI的OAuth UseOAuthBearerAuthentication给出"序列包含多个元素"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文