没有实体框架的Asp.Net Owin身份验证

Pau*_*ett 5 c# asp.net oauth-2.0 owin asp.net-identity

我有一个拥有600,000多用户的现有网站,我选择的数据库是RavenDb(NoSql).

我目前正在使用一种简单形式的Owin身份验证来登录用户,只需在我的登录控制器上调用它:

            var identity = new ClaimsIdentity(new[] {
                            new Claim(ClaimTypes.Sid, user.Id), 
                            new Claim(ClaimTypes.Email, viewModel.EMail),
                            new Claim(ClaimTypes.NameIdentifier, user.ArtistName) 
                        },
                        DefaultAuthenticationTypes.ApplicationCookie,
                        ClaimTypes.Sid, ClaimTypes.Role);

            Authentication.SignIn(new AuthenticationProperties
            {
                IsPersistent = viewModel.RememberMe
            }, identity);
Run Code Online (Sandbox Code Playgroud)

现在我想允许我的用户使用外部提供商登录,例如facebook,google等,但如果我不需要,我不想使用UserManager抽象.

我需要用什么来使其工作?我想我需要编写ExternalLoginCallback代码等代码,但在此时我真正需要/不需要的东西很困惑.

Phi*_*son 3

您必须实现外部提供程序向其发出 POST 请求的返回端点,然后在确定您信任 post 参数中的声明后,执行与原始登录中相同的操作。

提供的实现具有像 <your-site>/signin-google 这样的方法作为返回 URL,提供商使用名为 SecureAuthenticationToken 之类的 post 参数执行 POST,您必须解析然后信任(或不信任)。无需返回文档,它采用 json (JWT) 或 samlp 格式,具体取决于外部提供商和协议。