我正在为 SharePoint 2010 开发一个小项目,该项目将允许用户使用他们的 OpenID 进行身份验证(以后可能还会更多)。
它目前的工作方式是我有一个基于 SQL 的成员资格和角色提供程序。我的登录页面使用 DotNetOpenAuth 向 OpenID 端点发送身份验证请求。如果我得到肯定的响应,我会从 OpenID 角色读取电子邮件地址,并为具有该电子邮件地址的 MembershipUser 创建一个会话(如果我知道他来自的端点)。如果该用户不存在,我将创建一个新的 MembershipUser 并将端点存储在评论属性中(这样您就不能简单地编辑自己的角色以作为另一个人的电子邮件地址登录)。
这可行,但问题在于创建会话。我目前使用以下代码执行此操作:
//authenticate
SecurityToken token = SPSecurityContext.SecurityTokenForFormsAuthentication(new Uri(SPContext.Current.Web.Url),userProvider,roleProvider,username,user.GetPassword());
SPFederationAuthenticationModule.Current.SetPrincipalAndWriteSessionToken(token);
但是,只有在会员提供者不加密密码时,该位才有效,因为一旦加密,我就不能只读取用户的密码并在该方法中使用它。
我希望找到一种让用户登录的方法,但我似乎找不到一种简单的方法来做到这一点。
使用
FormsAuthentication.SetAuthCookie(username, false);
只是创建一个异常(我认为这是因为该方法适用于标准 FBA,而不是基于声明的 FBA,但我只是在猜测。带有用户名和密码的内置 FBA 登录控件确实有效。)
System.ArgumentException: Exception of type 'System.ArgumentException' was thrown. Parameter name: encodedValue
at Microsoft.SharePoint.Administration.Claims.SPClaimEncodingManager.DecodeClaimFromFormsSuffix(String encodedValue)
at Microsoft.SharePoint.Administration.Claims.SPClaimProviderManager.GetProviderUserKey(String encodedSuffix)
at Microsoft.SharePoint.SPGlobal.CreateSPRequestAndSetIdentity(SPSite site, String name, Boolean bNotGlobalAdminCode, String strUrl, Boolean bNotAddToContext, Byte[] UserToken, String userName, Boolean bIgnoreTokenTimeout, Boolean bAsAnonymous)
at Microsoft.SharePoint.SPWeb.InitializeSPRequest()
at Microsoft.SharePoint.WebControls.SPControl.EnsureSPWebRequest(SPWeb web)
at Microsoft.SharePoint.WebControls.SPControl.SPWebEnsureSPControl(HttpContext context)
at Microsoft.SharePoint.ApplicationRuntime.BaseApplication.Application_PreRequestHandlerExecute(Object sender, EventArgs e)
at Microsoft.SharePoint.ApplicationRuntime.SPRequestModule.PreRequestExecuteAppHandler(Object oSender, EventArgs ea)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
长话短说,我想要一种无需使用密码即可为我的会员创建令牌的方法。
有没有人有这方面的经验,或者知道我如何才能得到我想要的东西?
提前致谢。