【发布时间】:2011-12-13 22:33:38
【问题描述】:
目前我正在使用 DotNetOpenAuth CTP 版本开发 OAuth2 授权服务器。我的授权服务器在 asp.net MVC3 中,它基于库提供的示例。在应用程序到达用户授权消费者客户端之前,一切正常。
我的 OAuth 控制器中有一个动作负责授权过程,与示例中的等效动作非常相似:
[Authorize, HttpPost, ValidateAntiForgeryToken]
public ActionResult AuthorizeResponse(bool isApproved)
{
var pendingRequest = this.authorizationServer.ReadAuthorizationRequest();
if (pendingRequest == null)
{
throw new HttpException((int)HttpStatusCode.BadRequest, "Missing authorization request.");
}
IDirectedProtocolMessage response;
if (isApproved)
{
var client = MvcApplication.DataContext.Clients.First(c => c.ClientIdentifier == pendingRequest.ClientIdentifier);
client.ClientAuthorizations.Add(
new ClientAuthorization
{
Scope = OAuthUtilities.JoinScopes(pendingRequest.Scope),
User = MvcApplication.LoggedInUser,
CreatedOn = DateTime.UtcNow,
});
MvcApplication.DataContext.SaveChanges();
response = this.authorizationServer.PrepareApproveAuthorizationRequest(pendingRequest, User.Identity.Name);
}
else
{
response = this.authorizationServer.PrepareRejectAuthorizationRequest(pendingRequest);
}
return this.authorizationServer.Channel.PrepareResponse(response).AsActionResult();
}
每次程序到达这一行:
this.authorizationServer.Channel.PrepareResponse(response).AsActionResult();
系统抛出异常,我研究过但没有成功。例外情况如下: LINQ to Entities 仅支持无参数构造函数和初始化程序。
堆栈跟踪:http://pastebin.com/TibCax2t
我所做的与示例唯一不同的是我使用实体框架的代码优先方法,我认为示例是使用自动生成实体的设计器完成的。
提前谢谢你。
【问题讨论】:
-
你发现了吗?我遇到了同样的问题。
标签: asp.net-mvc-3 dotnetopenauth oauth-2.0