它使用SimpleMembershipProvider
ASP.NET MVC 4 中的默认提供程序来创建或更新公共提供程序用户 ID 和本地用户之间的关联。基本上它会在webpages_OAuthMembership
表中添加一条记录。
这是被调用的相应代码WebSecurity.CreateOrUpdateOAuthAccount
:
public override void CreateOrUpdateOAuthAccount(string provider, string providerUserId, string userName)
{
this.VerifyInitialized();
if (userName.IsEmpty())
{
throw new MembershipCreateUserException(MembershipCreateStatus.ProviderError);
}
int userId = this.GetUserId(userName);
if (userId == -1)
{
throw new MembershipCreateUserException(MembershipCreateStatus.InvalidUserName);
}
int userIdFromOAuth = this.GetUserIdFromOAuth(provider, providerUserId);
using (IDatabase database = this.ConnectToDatabase())
{
if (userIdFromOAuth == -1)
{
if (database.Execute("INSERT INTO [" + OAuthMembershipTableName + "] (Provider, ProviderUserId, UserId) VALUES (@0, @1, @2)", new object[] { provider, providerUserId, userId }) != 1)
{
throw new MembershipCreateUserException(MembershipCreateStatus.ProviderError);
}
}
else if (database.Execute("UPDATE [" + OAuthMembershipTableName + "] SET UserId = @2 WHERE UPPER(Provider)=@0 AND UPPER(ProviderUserId)=@1", new object[] { provider, providerUserId, userId }) != 1)
{
throw new MembershipCreateUserException(MembershipCreateStatus.ProviderError);
}
}
}