当我注册以下using声明时:
using Microsoft.AspNetCore.Identity.UI;
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
命名空间“Microsoft.AspNetCore.Identity”中不存在“UI”类型或命名空间名称(缺少程序集引用?)
在我看来,一切都很顺利。我将 a 添加<PackageReference>到NuGet 包中Microsoft.AspNetCore.Identity.UI。但错误仍然存在。
我该如何解决这个问题?
我的.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SQLite" Version="3.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.1.1" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
和我的AssemblyInfo.cs:
using System;
using System.Reflection;
[assembly: Microsoft.AspNetCore.Identity.UI.UIFrameworkAttribute("Bootstrap4")]
[assembly: System.Reflection.AssemblyCompanyAttribute("ESporcum")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] …Run Code Online (Sandbox Code Playgroud) 我正在处理的一个项目由一个 Web API、一个单页 React 应用程序和一个移动应用程序组成。从每个客户端,用户需要提供他们的用户名和密码才能访问 Web API 的受保护部分。我已经设置了一个 Identity Server 4 身份验证服务器,它使用我自己的IProfileService和IResourceOwnerPasswordValidator接口实现,因为我使用的是 ASP.NET Core Identity。这允许 Identity Server 访问 ASP.NET Core Identity UserManager、RoleManager和SignInManagers以确定提供的用户名和密码是否有效。
我一直在使用的授权类型是“ResourceOwnerPassword”类型。我还没有将授权完全集成到单页应用程序中,但我可以将用户的用户名和密码传递给身份服务器,并生成一个令牌,我可以将其添加到我的 API 请求的标头中。
我对身份服务器和相关技术进行了更多研究,因为我对这一切都不熟悉。使用 ResourceOwnerPassword 授权类型似乎是不可取的。据我所知,似乎我应该使用隐式授权类型,但我不完全了解用户名和密码如何适应该流程。有没有人知道我应该使用哪种类型?我描述的系统是否只能使用ResourceOwnerPassword授权类型?
问题已经更新,以便更好地解释我的问题,
我只有这个控制器,
[Authorize]
public class IdeaManagementController : Controller
{
private IIdeaManagementService _ideaManagementService;
private ITenantService _tenantService;
private ITagService _tagService;
private IEmployeeIdeaCategoryService _ideaManagementCategoryService;
private static PbdModule _modul = PbdModule.IdeaManagement;
IAuthorizationService _authorizationService;
public IdeaManagementController(
IIdeaManagementService ideaManagementService,
ITenantService tenantService,
ITagService tagService,
IAuthorizationService authorizationService,
IEmployeeIdeaCategoryService ideaManagementCategoryService)
{
_ideaManagementService = ideaManagementService;
_tenantService = tenantService;
_tagService = tagService;
_authorizationService = authorizationService;
_ideaManagementCategoryService = ideaManagementCategoryService;
}
public async Task<IActionResult> IdeaCoordinator()
{
if (!await _authorizationService.AuthorizeAsync(User, "IdeaManagement_Coordinator"))
{
return new ChallengeResult();
}
var ideas = _ideaManagementService.GetByIdeaCoordinator(_tenantService.GetCurrentTenantId());
return View(ideas);
}
} …Run Code Online (Sandbox Code Playgroud) c# unit-testing xunit.net asp.net-core-mvc asp.net-core-identity
我有一个需要能够通过基于ASP.NETCore的Web应用程序以及Windows应用程序(.NET 4.6)创建用户的要求。可以使用同一用户登录网站和WindowsApp。所使用的凭据存储是SQL Server数据库。我将ASP.NET Core Identity与Web应用程序的默认PasswordHashing实现一起使用。但是我遇到的问题是在通过WindowsApplication创建用户时试图复制相同的PasswordHashing算法。最简单的方法是什么?
我在ASP.NET Core 2 Web应用程序中使用JWT令牌
如果JWT令牌失败,我仍然希望命中控制器方法,但ASP.NET Identity User对象将只为null.目前,如果身份验证失败,则不会输入控制器方法,因此我无法在方法中应用逻辑来处理我想要作为来宾处理的非身份验证用户,而不是阻止它们.
我的代码:
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication()
.AddJwtBearer(cfg =>
{
cfg.TokenValidationParameters = new TokenValidationParameters()
{
ValidIssuer = _config["Tokens:Issuer"],
ValidAudience = _config["Tokens:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Tokens:Key"]))
};
});
Run Code Online (Sandbox Code Playgroud)
用户登录时
private IActionResult CreateToken(ApplicationUser user, IList<string> roles)
{
var claims = new List<Claim>
{
new Claim(JwtRegisteredClaimNames.Sub, user.Id.ToString()),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(JwtRegisteredClaimNames.UniqueName, user.UserName)
};
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Tokens:Key"]));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var token = new JwtSecurityToken(
_config["Tokens:Issuer"],
_config["Tokens:Audience"],
claims.ToArray(),
expires: …Run Code Online (Sandbox Code Playgroud) c# jwt asp.net-core asp.net-core-webapi asp.net-core-identity
已经搜索了很长时间,但是没有找到任何有关如何以SMTP形式设置帐户/电子邮件确认的来源,而不是使用Razor类库的ASP Core 2.1项目的任何其他方式(如使用SendGrid / MailKit)。
在这方面有什么建议吗?在这方面如何使用IdentityUser?是否有必要首先搭建身份?请查看是否有任何专家可以在这方面提供帮助。
我已经从互联网上尝试了很多示例(例如,第一,第二和其他示例),并且一切正常,除了在成功登录和生成令牌后,表AspNetUserLogins和AspNetUserTokens不显示任何数据的事实。
为什么会发生这种情况,我该如何解决?
jwt .net-core asp.net-core asp.net-core-webapi asp.net-core-identity
在ConfigureServices启动方法中,在配置Identity服务期间,可以使用以下代码配置密码规则:
services.Configure<IdentityOptions>(options =>
{
options.Password.RequireDigit = false;
options.Password.RequireLowercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Password.RequiredLength = 6;
options.Password.RequiredUniqueChars = 2;
});
Run Code Online (Sandbox Code Playgroud)
在哪里options.Password调用Identity对象PasswordOptions.请注意我的安全性非常宽松,只是为了使Register操作更顺畅,而不必重复处理复杂的密码.
现在在我的注册页面中,我希望有一个GeneratePassword方法将PasswordOptions实例作为输入并生成符合这些选项的密码.我希望该对象具有与我在设置密码选项时使用的相同的值ConfigureServices.
有没有办法访问这些选项值?到目前为止,我唯一的解决方案是将密码选项存储在我appsettings.json的序列化中,PasswordOptions并使用该Options模式将一个注入PasswordOptions到我的Register页面中PageModel.但是,我可能不希望将选项存储在配置文件中,并且希望稍后在硬编码时访问它们ConfigureServices.
c# dependency-injection asp.net-core-mvc asp.net-core asp.net-core-identity
我们正在使用身份服务器授予对 apis 的访问权限。到目前为止,我们使用(或需要)的所有内容都是 ClientCredentials(机器到机器),其中不涉及用户。
现在我们得到了用户应该参与的要求,我们必须提供用户权限。
我已经阅读了很多关于 Granttypes: Implicit, Authorization code, Hybrid 等...但仍然没有找到关于最佳实践的明确答案。
有没有办法在 access_token 中集成用户权限(这也是一个好主意吗?)。AspNetIdentity 已经集成并且表存在于 identityserver 数据库中。
services.AddIdentity<User, IdentityRole>()
.AddEntityFrameworkStores<IdentityContext>()
.AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)
如何发送客户端凭据和用户凭据,以便我们的身份服务器也可以收集用户信息(权限、声明、角色等...)?
任何帮助都受到高度赞赏。
谢谢
因此,该方法SignInManager.PasswordSignInAsync有一个最后一个参数lockoutOnFailure,如果该参数为真,则会在用户输入错误凭据时锁定用户。但是已经有一个名为的属性MaxFailedAccessAttempts,它在(默认情况下)5 个成功事件之后锁定用户。
我在这里有些困惑,无法根据第 4 个参数找到此方法如何工作的答案。如果已经设置了何时锁定的选项,为什么我们需要设置 lockoutOnFailure?我不想将其设置为 true。
我如何理解它的工作原理:
如果lockoutOnFailure: true,那么即使这是用户第一次尝试登录,如果他们输入错误的凭据,他们也会被锁定。如果lockoutOnFailure: false,那么即使这是他们的第 5 次尝试,如果他们输入了错误的凭据,他们也不会被锁定。我不希望这两种情况都发生,所以我不想将它设置为任何一个值。我该怎么办?还是我理解的方法不对?