如何从特定角色获得所有用户?
var users = Membership.GetAllUsers();
Run Code Online (Sandbox Code Playgroud)
获得所有角色的所有用户.
它返回一个列表MembershipUser,但没有角色属性.
谢谢
如何在服务器端 Blazor 中使用 OIDC 身份验证?
我使用了这个方法,但不知何故它不正确,因为@attribute [AllowAnonymous]实际上不起作用。所以我使用该[Authorized]属性而不是[AllowAnonymous]然后删除RequireAuthenticatedUser,但是OIDC不会将客户端重定向到服务器登录页面。
我查看了Steve Sanderson 的关于 Blazor 中的身份验证和授权的 GitHub 文章,但他没有谈论 OIDC。
这是我的启动课程:
services.AddAuthentication(config =>
{
config.DefaultScheme = "Cookie";
config.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookie")
.AddOpenIdConnect("oidc", config =>
{
config.Authority = "https://localhost:44313/";
config.ClientId = "client";
config.ClientSecret = "secret";
config.SaveTokens = true;
config.ResponseType = "code";
config.SignedOutCallbackPath = "/";
config.Scope.Add("openid");
config.Scope.Add("api1");
config.Scope.Add("offline_access");
});
services.AddMvcCore(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser() // site-wide auth
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
});
Run Code Online (Sandbox Code Playgroud) asp.net-authentication asp.net-core blazor blazor-server-side
它们是如何连接的?我可以使用HttpContext.SignInAsync, 然后HttpContext.User设置为提供的身份,但是我有一个身份和多种身份验证方式 - 如果用户以客户身份登录然后移动到 AdminPanel 会怎样?
我知道这个问题可能会收到一些downvotes,但是我在Google上搜索了三天,没有真正可用的结果.
我在Visual Studio中创建了一个默认的ASP.NET Core 1.0 RC1项目,具有个人用户帐户身份验证/授权.这一切都很简单,因为该项目是脚手架使用Microsoft.AspNet.Authentication.Cookies,VS 2015完成所有繁重的工作.
但是,我们希望从同一个项目(使用相同的数据库,用户,声明等)公开API,这些API将从移动设备甚至一些简单的SPA中使用.这样,我们需要为API使用类似JWT的东西(有很多关于如何使用WebAPI执行此操作的教程).
我们希望使用MVC(而不是SPA)方式来执行主项目,以利用视图/控制器脚手架以及Visual Studio可以提供的所有内容.
有许多仅限MVC或仅支持WebAPI的教程,但您能指出我如何将它们混合在一起?
有没有办法只在整个系统范围内使用JWT和MVC和WebAPI?
先感谢您.
c# asp.net-authentication asp.net-web-api asp.net-core-mvc asp.net-core
在某些情况下,例如单页应用程序,最终可能会有多种身份验证方法.例如,您的应用程序可能会使用基于cookie的身份验证来登录JavaScript请求的承载身份验证.在某些情况下,您可能有多个身份验证中间件实例.例如,两个cookie中间件,其中一个包含基本身份,另一个是在多因素身份验证触发时创建的,因为用户请求了需要额外安全性的操作.
例:
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationScheme = "Cookie",
LoginPath = new PathString("/Account/Unauthorized/"),
AccessDeniedPath = new PathString("/Account/Forbidden/"),
AutomaticAuthenticate = false
});
app.UseBearerAuthentication(options =>
{
options.AuthenticationScheme = "Bearer";
options.AutomaticAuthenticate = false;
});
Run Code Online (Sandbox Code Playgroud)
但是它仅描述了如何使用Bearer或Cookie auth.不清楚的是其他组合是有效的,或者如何正确地向客户发放承载或cookie.
怎么能实现呢?
asp.net asp.net-mvc asp.net-authentication katana asp.net-core
现在我知道有很多关于这个的帖子,但我的情况有所不同.所以请耐心等待.
当我在.Net Framework上创建WebApi并选择个人用户帐户时,它已经为我提供了一个外部身份验证的工作代码.

有AccountController,Startup.auth.cs和其他具有外部身份验证代码的文件

现在我知道.net核心已经发生了变化.但个人用户帐户的net.core web api与它没有任何相似之处.
当我尝试在.net Core上使用WebApi时,它只为我提供了一个选择Azure应用程序的选项.在下图中,使用.net核心上的WebApi,蓝色指向的下拉列表仅提供一个Azure AD b2c应用程序选项.没有帐户控制器是脚手架,也没有其他配置文件用于外部身份验证.
我试过这些链接:https: //docs.microsoft.com/en-us/aspnet/web-api/overview/security/external-authentication-services
https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/
但第一个链接是针对.net框架,但对我没有帮助.第二只适用于Web应用程序的asp.net核心,但不是的WebAPI
我需要在web api中进行外部身份验证,因为我希望所有来自Web或移动设备的用户都可以通过Google或Facebook进行身份验证.请任何人指出我正确的方向.我在这里错过了一些东西.有没有文件可以帮我解决这个问题?
authentication asp.net-authentication .net-core asp.net-core-webapi asp.net-core-2.0
我有以下代码,我想了解这两种扩展方法之间有什么区别。每一个人都做什么?
services.AddAuthentication (JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer (options => options.TokenValidationParameters = new TokenValidationParameters {
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ClockSkew = TimeSpan.Zero,
ValidIssuer = Issuer,
ValidAudience = Audience,
IssuerSigningKey = new SymmetricSecurityKey(secret)
});
services.AddAuthorization();
Run Code Online (Sandbox Code Playgroud)
谢谢,
c# asp.net-authorization asp.net-authentication jwt asp.net-core
我的 ASP.NET Core 应用程序使用“开箱即用”的外部登录身份验证。我想要实现的 - 在 facebook 挑战中,我想包装重定向 url 并将其作为 json 返回以在 jquery 前端使用。但请求结束后,我在浏览器中看到 500 错误,在应用程序控制台中看到下一个错误:
失败:Microsoft.AspNetCore.Server.Kestrel[13] 连接 ID“0HLV651D6KVJC”,请求 ID“0HLV651D6KVJC:00000005”:应用程序抛出了一个未处理的异常。System.InvalidOperationException:响应内容长度不匹配:写入的字节太少(470 个中的 0 个)。
我的外部登录操作,没什么特别看的
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public IActionResult ExternalLogin(string provider, string returnUrl = null)
{
// Request a redirect to the external login provider.
var redirectUrl = Url.Action(nameof(ExternalLoginCallback), "Account", new { returnUrl });
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
return Challenge(properties, provider);
}
Run Code Online (Sandbox Code Playgroud)
脸书认证配置:
services.AddAuthentication().AddFacebook(facebookOptions =>
{
facebookOptions.AppId = Configuration["Authentication:Facebook:AppId"];
facebookOptions.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
facebookOptions.Events.OnRedirectToAuthorizationEndpoint =
async (x) =>
{
UTF8Encoding …Run Code Online (Sandbox Code Playgroud) 我有一个AngularJS + MVC + WebAPI,我正在尝试: - 使用标准(个人帐户)进行MVC身份验证; - 使用相同的用户和密码进行基于WebAPI的身份验证.
问题,从AngularJS一切正常,cookie交换发生,Web API返回值,但是当我试图从Postman访问WebAPI时,我得到一个重定向到登录页面而不是401 Unauthorized.
实现这一目标的最简单方法是什么?我是否必须子类授权并手动实现逻辑?
谢谢
asp.net-mvc asp.net-authentication asp.net-web-api asp.net-identity
我正在尝试在我的ASP.NET Core 2.0应用程序中实现LinkedIn/OAuth身份验证,我需要将范围设置为{ "r_basicprofile", "r_emailaddress" }以便我可以使用用户的电子邮件,个人资料图像等.
当我尝试在以下代码中设置范围时,我收到以下错误:
无法将属性或索引器"OAuthOptions.Scope"分配给 - 它是只读的.
这是代码:
services.AddOAuth(CookieAuthenticationDefaults.AuthenticationScheme, options => {
options.SignInScheme = "LinkedIn";
options.ClientId = "1234567890";
options.ClientSecret = "1234567890";
options.CallbackPath = "/linkedin-callback";
// Configure the LinkedIn endpoints
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,first-name,last-name,email-address,picture-url,picture-urls::(original))",
options.Scope = { "r_basicprofile", "r_emailaddress" };
options.Events = new OAuthEvents
{
OnCreatingTicket = OnCreatingTicketLinkedInCallBack,
OnTicketReceived = OnTicketReceivedCallback
};
})
Run Code Online (Sandbox Code Playgroud)
知道如何设置范围吗?
PS我试图改编我的ASP.NET Core 1.1中的代码.此代码在ASP.NET Core 1.1应用程序中运行良好.
asp.net-core ×6
c# ×3
asp.net-mvc ×2
.net-core ×1
asp.net ×1
blazor ×1
jwt ×1
katana ×1
oauth ×1