标签: asp.net-core-identity

ASP.NET Core 和 Angular:Microsoft 身份验证

目前,我正在尝试向我的 ASP.NET Core Web 应用程序添加第三方身份验证。今天我已经成功地实现了 Facebook 身份验证。这已经很困难了,因为文档只提到了带有剃刀页面的 ASP.NET 应用程序的 Facebook 身份验证(https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/facebook-logins?视图=aspnetcore-2.2)。文档中没有写任何关于为 Angular 应用程序实现这一点的内容。

这是我为 ASP.NET Core + Angular + FB auth 找到的最完整的演练:https : //fullstackmark.com/post/13/jwt-authentication-with-aspnet-core-2-web-api-angular-5 -net-core-identity-and-facebook-login

我正在使用 Microsoft.AspNetCore.Identity,这个包已经为你管理了很多。但是我找不到如何开始在 Web 应用程序中实现 Microsoft、Google 甚至 Twitter 登录。文档似乎没有涵盖那部分......

我的 GitHub 存储库:https : //github.com/MusicDemons/MusicDemons-ASP-NET

任何人都有这方面的经验?

google-login facebook-login asp.net-core asp.net-core-identity angular

0
推荐指数
1
解决办法
2350
查看次数

问题添加 IdentityDbContext

我正在使用Asp Net core 3并尝试添加身份核心。当我添加IdentityDbContext它时会出现错误,如果我更改IdentityDbContextDbContext错误就消失了。同样的问题是当我尝试添加SQL severusingIdentityDbContext但在 using 时没有错误DbContext。我收到以下错误“没有从IdentityDbContext到的隐式引用转换Microsoft.EntityFrameworkCore.DbContext点击查看错误 我添加了以下 NuGet 包Microsoft.AspNetCore.Identity.EntityFrameworkCoreMicrosoft.EntityFrameworkCore.Sqlserver。请帮忙。

c# asp.net-identity asp.net-core asp.net-core-identity

0
推荐指数
1
解决办法
61
查看次数

在 ASP .NET Core 3.1 中使用 Linkedin 注册/登录

我正在为我的 Web 项目使用 ASP .NET Core 3.1 个人身份验证模板。我正在尝试集成 LinkedIn 外部登录,但不知道如何正确执行。

我使用以下链接寻求帮助: OAuth LinkedIn Integration

这是我的代码:

services.AddAuthentication()
            .AddOAuth("LinkedIn", "LinkedIn", options =>
            {
                IConfigurationSection linkedinAuthNSection =
                Configuration.GetSection("Authentication:Linkedin");

                options.ClientId = linkedinAuthNSection["ClientId"];
                options.ClientSecret = linkedinAuthNSection["ClientSecret"];

                options.CallbackPath = new PathString("/signin-linkedin");
                options.AuthorizationEndpoint = "https://www.linkedin.com/oauth/v2/authorization";
                options.TokenEndpoint = "https://www.linkedin.com/oauth/v2/accessToken";
                options.UserInformationEndpoint = "https://api.linkedin.com/v1/people/~:(id,formatted-name,email-address,picture-url)";
                options.Scope.Add("r_liteprofile");
                options.Scope.Add("r_emailaddress");
                options.Scope.Add("w_member_social");
            });
Run Code Online (Sandbox Code Playgroud)

但是我在OnGetCallbackAsync处理程序中遇到错误:

var info = await _signInManager.GetExternalLoginInfoAsync();
Run Code Online (Sandbox Code Playgroud)

info接收到的值null

c# asp.net-core-identity asp.net-core-2.1 .net-core-3.1 asp.net-core-3.1

0
推荐指数
1
解决办法
1326
查看次数

.NET Core Web API HttpContext.User.Claims 和 HttpContext.User.Identity 在控制器中始终为 null

我在后端使用 ASP.NET Core Web API,并在 Blazor WASM 客户端的 httpClient 标头中使用 JWT 令牌(我不在 cookie 中存储 JWT 令牌)。

问题是,虽然用户已登录并且身份验证和授权工作没有问题,但在每个控制器(继承自ControllerBase)中始终:

  • HttpContext.User.Identity.IsAuthenticated是假的
  • HttpContext.User.Identity.Name一片空白
  • HttpContext.User.Claims一片空白

但请求具有 JWT 令牌(Request.Headers["Authorization"][0]等于Bearer eyJhbGciOiJIUzI1...)并且[Authorize]属性正常工作。

这是我的startup.cs的样子:

services.AddIdentity()
            
services.AddSingleton<IAuthorizationPolicyProvider, AuthorizeExPolicyProvider>();

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                .AddJwtBearer(options =>
                              options.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer = false,
                    ValidateAudience = false,
                    ValidateLifetime = true,
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey = new SymmetricSecurityKey(
                        Encoding.UTF8.GetBytes(Configuration["jwt:key"])),
                    ClockSkew = TimeSpan.Zero
                });

services.AddAuthorization(options =>
            {
            });
Run Code Online (Sandbox Code Playgroud)

我还按正确的顺序调用了中间件:

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers(); …
Run Code Online (Sandbox Code Playgroud)

c# jwt asp.net-core-webapi asp.net-core-identity

0
推荐指数
1
解决办法
7653
查看次数

PasswordSignInAsync()似乎在没有任何错误的情况下阻塞

我正在尝试使用ASP.NET Core Identity 2.0在我现有的应用程序中设置身份验证.当我使用自己的数据库模式和类时,我有自己的User类,我不得不创建自定义UserStore和自定义UserManager.

所以我在AccountController中有我的登录功能:

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null)
    {
        ViewData["ReturnUrl"] = returnUrl;
        if (ModelState.IsValid)
        {
            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, set lockoutOnFailure: true
            var result = await _signInManager.PasswordSignInAsync(model.Login, model.Password, model.RememberMe, lockoutOnFailure: false);
            if (result.Succeeded)
            {
                _logger.LogInformation("User logged in.");
                return RedirectToLocal(returnUrl);
            }
            if (result.IsLockedOut)
            {
                _logger.LogWarning("User account locked out.");
                return RedirectToAction(nameof(Lockout));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Connection failed.");
                return View(model); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-identity asp.net-core asp.net-core-identity

-1
推荐指数
1
解决办法
145
查看次数