我正在根据以下文章测试基于JWT令牌的安全性的实现.我已成功从测试服务器收到一个令牌.我无法弄清楚如何让Chrome POSTMAN REST客户端程序在标头中发送令牌.

我的问题如下:
1)我使用正确的标题名称和/或POSTMAN界面吗?
2)我需要基于64编码令牌吗?我以为我可以把令牌送回来.
我正在使用ASP.NET Core应用程序.我正在尝试实现基于令牌的身份验证,但无法弄清楚如何使用新的安全系统.
我的场景: 客户端请求令牌.我的服务器应该授权用户并返回access_token,客户端将在以下请求中使用该access_token.
这里有两篇关于正确实现我需要的文章:
问题是 - 对于我来说,如何在ASP.NET Core中执行相同的操作并不明显.
我的问题是:如何配置ASP.NET Core Web Api应用程序以使用基于令牌的身份验证?我应该追求什么方向?你有没有写过关于最新版本的文章,或者知道我在哪里可以找到它?
谢谢!
c# authentication authorization asp.net-web-api asp.net-core
在Web API 2中,您曾经能够通过中间件设置OAuth授权服务器来创建端点以发出令牌,如下所示:
//Set up our auth server options.
var OAuthServerOptions = new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
Provider = new SimpleAuthorizationServerProvider()
};
// Sets up the token issue endpoint using the options above
app.UseOAuthAuthorizationServer(OAuthServerOptions);
Run Code Online (Sandbox Code Playgroud)
也许我错过了它,但我想弄清楚如何在ASP.NET Core中做到这一点.我查看了源代码(https://github.com/aspnet/Security),但我真的没有看到类似的东西.有没有新的方法来实现这一目标?我是否需要创建一个控制器并自己完成?
我看到如何通过中间件设置OAuth身份验证,但这涉及我从API发出声明的授权部分.
我有一个传统的ASP.NET应用程序,我想转移到ASP.NET 5(vNext).我这样做是为了学习练习.
我当前的应用使用基于表单的身份验证.但是,我想使用OAuth.我正在查看安全模块,很好奇应该用于OAuth.我看到的选项Microsoft.AspNet.Authentication.OAuth和Microsoft.AspNet.Authentication.OAuthBearer.
以下哪些用于让用户登录?
有没有人知道显示这些实际情况的样本/示例?
在ASP.NET Core 1.x中,我可以在Configure中使用身份验证方法,但现在在ASP.NET Core 2.0中,我必须在ConfigureServices中设置所有内容,并且无法在Configure方法中对其进行 配置.例如
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication()
.AddCookie()
.AddXX();
}
Run Code Online (Sandbox Code Playgroud)
然后在
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
....
app.UseAuthentication();
}
Run Code Online (Sandbox Code Playgroud)
在过去,我可以使用类似的东西
app.UseOpenIdConnectAuthentication();
Run Code Online (Sandbox Code Playgroud)
我不能再像这样配置它了.
那么我现在如何在ASP.NET Core 2.0中使用这样的东西呢?
app.Map(new PathString("/MyPath"), i => i.UseMyAuthMethod());
Run Code Online (Sandbox Code Playgroud) 我正在尝试在ASP.NET 5中实现OAuth承载令牌身份验证,并且很难找到如何执行此操作的示例,因为ASP.NET 5中的OWIN内容已经发生了变化.
例如IApplicationBuilder.UseOAuthAuthorizationServer()和IApplicationBuilder.UseOAuthBearerAuthentication()要不再存在,要么我错过了引用?
任何指针都将非常感激.
Pinpoint帮助我从发射台上取下这个原型 - 我非常接近,除了:
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-beta6"
}
}
Run Code Online (Sandbox Code Playgroud)
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta6",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta6",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta6",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta6",
"System.IdentityModel.Tokens": "5.0.0-beta6-207211625",
"Serilog.Framework.Logging": "1.0.0-beta-43",
"Microsoft.AspNet.Authentication.OAuthBearer": "1.0.0-beta6"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini"
},
"frameworks": {
"dnx451": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
]
}
Run Code Online (Sandbox Code Playgroud)
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{ …Run Code Online (Sandbox Code Playgroud) 我需要获得提出请求的用户ID.在以前的Identity版本中,我可以这样做:
User.Identity.GetUserId();
Run Code Online (Sandbox Code Playgroud)
但它似乎不再可用了.
还有类似的东西:
User.GetUserId();
Run Code Online (Sandbox Code Playgroud)
但它始终返回null,即使正确设置了User.Identity.IsAuthenticated并且正确设置了User.Identity.Name.
我应该用它做什么?
编辑:我的authenticaton逻辑基于[默认的Visual Studio 2015模板],到目前为止我的身份没有太大变化,所以如果你想检查它是如何完成的,你可以在我粘贴的github链接上看到它.
从本质上讲,这是对近两年前这个问题的更新,@ Pinpoint的AspNet.Security.OpenIdConnect.Server名声非常有帮助.
我会把咆哮放在最底层,让所有关心自己沉迷于沮丧的开发者凌晨四点亵渎的人.
我正在开始一些新项目,并且出于我自己的原因,我想使用最新版本的ASP.NET技术(ASP.NET 5 vNext和MVC 6)来开始.
通常,OAuth2可用于身份验证.
ASP.NET曾经支持使用OAuth2创建令牌,但它不再支持,也不会支持,显然它不是很好.有一些帮助,但我仍然有点迷失如何将它与ASP.NET身份和新Authorize属性联系起来.
所以我的实际问题.
AccountController快速创建帐户并为社交登录或个人登录提供令牌,具有可爱的ASP.NET Identity用户存储以保持整洁,密码恢复以及一系列标准,现代帐户资料和授权屏幕以确认权限请求("XXX想要访问您的帐户,这样可以吗?"等)据我所知,我不能使用ASP.NET 5的新策略授权IdentityServer3.我不能成为唯一想要这种架构的人,有人完成了这个吗?
我觉得每次来保护我的应用程序,我都会发明一点轮子.
我已经离开授权的东西超过一年,但我回来了,男孩的事情发生了变化.而且它与OWIN,Katana,ASP.NET Identity, …
我一直在尝试使用简单的密钥创建和签署JwtSecurityToken.经过大量研究后,我发现所有示例似乎都使用InMemorySymmetricSecurityKey类,但不幸的是,这个类似乎不存在于最新版本的System.IdentityModel库中.
这些是我正在使用的依赖项:
"System.IdentityModel.Tokens": "5.0.0-rc1-211161024",
"System.IdentityModel.Tokens.Jwt": "5.0.0-rc1-211161024"
Run Code Online (Sandbox Code Playgroud)
我也尝试使用它的基类SymmetricSecurityKey但是在尝试创建令牌时我得到以下异常:
"Value cannot be null.\r\nParameter name: IDX10000: The parameter 'signatureProvider' cannot be a 'null' or an empty object."
Run Code Online (Sandbox Code Playgroud)
这是抛出异常的代码:
public static string CreateTokenHMAC()
{
HMACSHA256 hmac = new HMACSHA256(Convert.FromBase64String("test"));
var key = new SymmetricSecurityKey(hmac.Key);
var signingCredentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256Signature);
JwtSecurityToken token = _tokenHandler.CreateJwtSecurityToken(new SecurityTokenDescriptor()
{
Audience = AUDIENCE,
Issuer = ISSUER,
Expires = DateTime.UtcNow.AddHours(6),
NotBefore = DateTime.Now,
Claims = new List<Claim>()
{
new Claim(ClaimTypes.Email, "johndoe@example.com")
},
SigningCredentials …Run Code Online (Sandbox Code Playgroud)