标签: openiddict

IdentityServer4与AspNet.Security.OpenIdConnect.Server对比OpenIddict

为了理解我可以用于OpenId Connect Server实现的内容,我已经研究了它们各自的含义:

  • IdentityServer4:

    ASP.NET Core 2的OpenID Connect和OAuth 2.0框架.

  • AspNet.Security.OpenIdConnect.Server:

    对于两个ASP.NET核心的1.x/2.x和OWIN /卡塔纳3.X/4.x的一种先进的OAuth2/ID连接服务器框架,目的是提供一个低级别的,协议的第一种方法.

  • OpenIddict:

    OpenIddict旨在提供一种简单易用的解决方案,以在任何ASP.NET Core 1.x或2.x应用程序中实现OpenID Connect服务器.

    OpenIddict基于AspNet.Security.OpenIdConnect.Server控制OpenID Connect身份验证流程,可以与任何成员资格堆栈一起使用,包括ASP.NET核心身份.

  • 还检查了所有这些都使用ASP.NET Core Identity作为会员系统.

所以我目前的理解是,IdentityServer4并且OpenIdConnect.Server是解决同一问题的两个替代框架.主要区别在于受支持的ASP.NET Core版本列表.

关于Openiddict- 它是一种基于简化服务器创建的扩展AspNet.Security.OpenIdConnect.Server.

我错过了什么,或者这是一般的事情吗?

openid-connect asp.net-core identityserver4 openiddict

16
推荐指数
1
解决办法
5977
查看次数

带有 React 的 ASP.NET Core 身份 SPA

我对在 React SPA 中使用 ASP.NET Core Identity 感到困惑和迷茫。

我已经多次阅读有关 ASP.NET Core Identity 的 Microsoft 文档,主要集中在Identity with SPA 部分,但我必须承认我仍然不清楚如何将 React SPA 与 ASP.NET Core Identity 绑定。

这些是我偶然发现的拦截器:

  • 该文档假设我想使用IdentityServer,但我没有。我更喜欢Openiddict,但我不知道如何切换。最糟糕的是,我对 IdentityServer 或 Openiddict 的作用并不完全清楚。我知道他们为 JWT 令牌提供 OpenId 连接并保护我的 REST 端点,但他们如何做到这一点对我来说仍然不清楚。

  • 专注于 React SPA 的 Microsoft 文档都使用“方便的”托管 React SPA 和 API 后端作为一个单元。这很不幸,因为我不想要那样。我的 React SPA 与 API 完全解耦并分离,它们将单独托管。总而言之,我不希望我的 React SPA 与 API 后端在同一个解决方案中。

  • Microsoft 文档中的大多数示例使用实体框架作为 ORM。我不会。我将改用 Dapper。好消息是,有一节更好地解释了 ASP.NET Core Identity 的自定义存储提供程序,而且我正在研究 ASP.NET Core …

reactjs identityserver3 asp.net-core openiddict asp.net-core-identity

11
推荐指数
1
解决办法
706
查看次数

如何到达openiddict授权服务器的注册页面?

我已将opeiddict构建为单独的Web应用程序作为授权服务器.我遇到了一个小问题,就是我可以通过客户端Web应用程序的链接直接进入用户注册页面.现在我可以进入登录页面,作为示例示例:

public ActionResult SignIn() {
           // Instruct the OIDC client middleware to redirect the user agent to the identity provider.
           // Note: the authenticationType parameter must match the value configured in Startup.cs
           return new ChallengeResult(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties {
               RedirectUri = "/"
           });
       }
Run Code Online (Sandbox Code Playgroud)

有没有办法从客户端应用程序转到身份验证服务器帐户/注册?

.net-core asp.net-core openiddict

10
推荐指数
1
解决办法
264
查看次数

使用ASP.NET Core REST API在SPA(Angular 2)中进行社交注册

我已经实现了使用ASP.NET Core WebApi作为后端的简单Angular 2应用程序.对于身份验证,我添加了"/ login"路由,该路由生成JWT访问权限并刷新令牌,而令牌又由SPA存储在localStorage中并用于HTTP请求.

现在我想整合社交注册功能,以便用户可以使用Facebook按钮登录.从用户的角度来看,我想将其分为3个步骤:

  1. 点击Facebook注册按钮并重定向到Facebook网站(登录并确认我的应用程序请求).
  2. 点击确认并重定向到我的SPA所在/注册页面,其中他的名字已经从Facebook个人资料中填写
  3. 填写剩余的字段(如他最喜欢的玩具)并点击"完成注册"

在此注册后,如果用户再次通过facebook点击注册,他将被重定向到Facebook(如果他已经登录),他会自动重定向到服务器路由,检查这样的用户是否已经注册,如果是,则将其重定向到SPA主页

如何在我的应用程序中正确集成这样的工作流程?注意:我想在我的Angular2应用程序中执行身份验证和注册,而不是在不同的auth服务器上执行.

openid-connect oauth2 asp.net-core openiddict angular

9
推荐指数
1
解决办法
1380
查看次数

你如何解决AspNet Core缺少的依赖关系?

所以我对我的project.json进行了更改,导致重新恢复,这会产生一堆无法解析的依赖项.你怎么知道这里发生了什么?这肯定是有效的,因为我写了很多针对这个project.json文件的代码.

"dependencies": {
    "EntityFramework.Commands": "7.0.0-*",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-*",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-*",
    "Microsoft.AspNet.Authentication.JwtBearer": "1.0.0-rc2-*",
    "Microsoft.AspNet.Mvc": "6.0.0-*",
    "Microsoft.AspNet.Hosting": "1.0.0-*",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
    "Microsoft.AspNet.StaticFiles": "1.0.0-*",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-*",
    "AspNet.Security.OAuth.Validation": "1.0.0-*",
    "OpenIddict": "1.0.0-*",
    "System.IdentityModel.Tokens.Jwt": "5.0.0-rc2-301150021",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-15958",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-15958",
    "EntityFramework.Sqlite": "7.0.0-rc2-*",
    "EntityFramework.Sqlite.Design": "7.0.0-rc1-final",
    "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*"
  }



 NotFound https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.staticfiles/index.json 514ms
  NotFound https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.identity.entityframeworkcore/index.json 498ms
  NotFound https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.hosting.abstractions/index.json 1743ms
  NotFound https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.authentication/index.json 1745ms
  NotFound https://api.nuget.org/v3-flatcontainer/microsoft.extensions.fileproviders.embedded/index.json 1791ms
  NotFound https://api.nuget.org/v3-flatcontainer/microsoft.extensions.fileproviders.composite/index.json 1859ms
  NotFound https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.identity/index.json 1892ms
  NotFound https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.cors/index.json 1901ms
  NotFound https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.mvc/index.json 1875ms
  NotFound https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.hosting/index.json 1887ms

NotFound https://api.nuget.org/v3-flatcontainer/openiddict/index.json 1720ms
Run Code Online (Sandbox Code Playgroud)

aspnet-contrib asp.net-core openiddict

7
推荐指数
1
解决办法
7078
查看次数

使用Openiddict的ASP.NET Core 1.0 OAuth服务器

我想使用Openiddict OAuth来保护我的ASP.NET Core 1.0 Web应用程序中的api端点.该api终端将通过手机应用程序被调用,用户必须输入用户名和密码登录.

流程如下:

  • 用户可以通过Web应用程序注册和登录: https://www.domain.com
  • 用户安装手机应用程序,他们可以使用手机应用程序登录和注册.登录,注册和数据访问通过api端点完成:示例:https://www.domain.com/api/service/getsomedata

如何配置Openiddict OAuth,以便使用OAuth保护API端点?

oauth asp.net-core-mvc asp.net-core asp.net-core-1.0 openiddict

7
推荐指数
1
解决办法
2342
查看次数

.NET Core WebAPI + OpenIdDict(凭据流)和Angular2客户端:401成功登录后(完全重新登录)

我正在尝试使用凭证流创建一个使用OpenIdDict保护的.NET Core Web API的Angular2 SPA.在为这个问题创建一个repro解决方案时,我还详细介绍了自述文件中的所有步骤,所以希望这篇文章对像我这样的新手有用.请在这些存储库中找到完整的repro解决方案:

至于服务器端,我按照OpenIdDict提供的关于此流程的示例(https://github.com/openiddict/openiddict-samples/blob/master/samples/PasswordFlow).以下是最相关的位Startup:

public void ConfigureServices(IServiceCollection services)
{
    services.AddCors();

    services.AddEntityFrameworkSqlServer()
        .AddDbContext<CatalogContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("Catalog")))
        .AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("Catalog")));

    services.AddIdentity<ApplicationUser, ApplicationRole>()
        .AddEntityFrameworkStores<ApplicationDbContext>()
        .AddDefaultTokenProviders();

    services.AddOpenIddict<ApplicationDbContext>()
        .DisableHttpsRequirement()
        .EnableTokenEndpoint("/connect/token")
        .EnableLogoutEndpoint("/connect/logout")
        .EnableUserinfoEndpoint("/connect/userinfo")
        .AllowPasswordFlow()
        .AllowRefreshTokenFlow()
        .AddEphemeralSigningKey();

    services.AddMvc()
        .AddJsonOptions(options =>
        {
            options.SerializerSettings.ContractResolver =
                new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
        });

    // add my services
    // ...

    services.AddTransient<IDatabaseInitializer, DatabaseInitializer>();
    services.AddSwaggerGen();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, 
    ILoggerFactory loggerFactory,
    IDatabaseInitializer databaseInitializer)
{
    loggerFactory.AddConsole(Configuration.GetSection("Logging"));
    loggerFactory.AddDebug(); …
Run Code Online (Sandbox Code Playgroud)

asp.net authentication asp.net-web-api openiddict angular

7
推荐指数
1
解决办法
1481
查看次数

如何在asp.net core中从JWT检索ClaimsPrincipal

在我的解决方案中,我有两个项目。1) Web API 和 2) MVC。我正在使用 ASP.NET Core。API 发出 JWT 令牌,MVC 使用它来获取受保护的资源。我正在使用openiddict库来发布 JWT。在 MVC 项目中,在 AccountController Login 方法中,我想检索 ClaimsPrincipal (使用 JwtSecurityTokenHandler ValidateToken 方法)并分配给 HttpContext.User.Claims 和 HttpContext.User.Identity。我想将令牌存储在会话中,并且对于成功登录后的每个请求,将其在标头中传递给 Web API。我可以成功地发出 JWT 并在 MVC 项目中使用它,但是当我尝试检索 ClaimsPrincipal 时,它会抛出一个错误。首先,我什至不确定从 JWT 检索 ClaimsPrinciapal 是否是正确的方法。如果是的话,前进的方向是什么?

WebAPI.启动.CS

public class Startup
{
    public static string SecretKey => "MySecretKey";
    public static SymmetricSecurityKey SigningKey => new SymmetricSecurityKey(Encoding.ASCII.GetBytes(SecretKey));

    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            .AddEnvironmentVariables();
        Configuration = builder.Build(); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-mvc asp.net-core openiddict

6
推荐指数
2
解决办法
9803
查看次数

Openiddict 自省不起作用(访问令牌无效。)

我有 3 个项目 1- SPA、2- Web API 项目、3- Identity(使用 openiddict、ASP.NET Core 2.0(OpenIddict.dll 版本 2.0.0.-rc2-0854)和 EF Core 进行设置。

\n\n

API 和 Identity Server 成功运行,可以获取 jwt 令牌,但是,当我尝试从具有授权属性的 API 方法获取值时,出现错误:

\n\n
WWW-Authenticate \xe2\x86\x92Bearer error="invalid_token", error_description="The access token is not valid." \n
Run Code Online (Sandbox Code Playgroud)\n\n

在 Application Insights 中,可以看到 POST /connect/introspect 被调用,结果依赖项结果代码:500 和依赖项代码:Http

\n\n

相同的代码以前可以工作,不确定哪些更改会破坏内省。

\n\n

API项目中的配置

\n\n
 services.AddAuthentication(options =>\n        {\n            options.DefaultScheme = OAuthIntrospectionDefaults.AuthenticationScheme;\n        })\n          .AddOAuthIntrospection(options =>\n          {\n              options.Authority = new Uri("http://localhost:49888");\n              options.ClientId = "my-resource-server";\n              options.ClientSecret = "ClientSecret";\n              options.RequireHttpsMetadata = false;\n          });\n        services.AddCors();           \n        services.AddMvc()\n            .AddJsonOptions(options …
Run Code Online (Sandbox Code Playgroud)

openiddict

6
推荐指数
1
解决办法
5031
查看次数

OpenId Connect更新SPA中的access_token

尝试在由以下组件组成的Web应用程序中实现OpenId Connect

  • 身份提供者
  • 资源服务器
  • 单页应用程序充当客户端。

身份提供者和资源服务器是同一应用程序。

SPA使用密码流来获取access_token并存储到cookie中。存储access_token到cookie中具有它的安全线程,但这是另外一回事了。

问题

access_token 由IdP发行的证书将在30分钟后过期,并且SPA需要续签令牌,而无需再次要求用户提供凭据。

IdP refresh_token与一起返回access_token。每当SPA 401从Resource Server 获取时,它都会发送refresh_token到IdP并重新获取access_token

问题

发送refresh_token到SPA是不好的做法

单页应用程序(通常实现隐式授予)在任何情况下都不应获得刷新令牌。这样做的原因是该信息的敏感性。您可以将其视为用户凭据,因为“刷新令牌”允许用户基本上永远保持身份验证。因此,您不能在浏览器中拥有此信息,必须将其安全地存储。

建议的解决方案

访问令牌过期后,假设用户的SSO会话尚未过期,则可以使用静默身份验证来检索新的令牌,而无需用户交互。

我认为,当IdP和资源服务器是同一应用程序时,静默身份验证不适用于密码流。access_token由IdP发布的信息仅是可用于在资源服务器/ IdP到期后针对其授权的信息,客户端如何说服 IdP发布新的access_token?(不发送refresh_token

找到angular-oauth2-oidc库,用于refresh_token续订access_token

在这种情况下续订的最佳实践/解决方案是什么access_token

技术细节

  • 身份提供者-ASP.NET Core + Openiddict库。
  • SPA-AngularJs应用程序。

oauth-2.0 openid-connect asp.net-core openiddict

6
推荐指数
1
解决办法
756
查看次数