在.Net核心中共享默认的OWIN标记

Ale*_*bel 7 token machinekey owin .net-core asp.net-core

我有基于.NET 4.5.1构建的授权服务器并使用Microsoft.Owin.Security.OAuth版本= 3.0.0 http://prntscr.com/hvwhl4 通过machinkey保护的令牌(OAuthAuthorizationServerOptions.AccessTokenFormat是默认值).我还在.NET 4.5.1上有许多应用程序使用者(资源服务器)来验证这些令牌http://prntscr.com/hvwwdu http://prntscr.com/hvwiwr.所有这些应用程序在web.config中都具有相同的machinkey

现在我尝试构建.net core 2.0应用程序,我需要使用来自我的Auth服务器(.net 4.5.1 owin 3.0.0)的相同令牌.如何在.net core 2.0中验证和读取来自Microsoft.Owin.Security.OAuth(3.0.0)令牌的声明?

一个注意事项:我无法更改我的Auth服务器并在Auth服务器中定义DataProtector.所以我需要找到一种方法如何使用现有的机器密钥在.net核心中"解码"OWIN令牌.

更新:所以我在github上打开了问题https://github.com/aspnet/Security/issues/1592

现在它已关闭,答案是:"关闭,因为没有计划支持这一点.您可以使用第三方令牌服务器(如Identity Server)发出可与两个系统一起使用的令牌.或者,您可以为ASP编写自定义代码.NET Core用于处理OWIN/Katana风格的令牌."

我找到了一种解决方案.我在Auth服务器中使用Autofac.Integration.Owin包和OAuthAuthorizationServerMiddleware来定义运行时从哪个资源服务器获取请求,然后定义我需要返回令牌的格式.

请在Auth服务器的Autofac配置下面找到一段代码: 在此输入图像描述

小智 4

我使用此包Owin.Token.AspNetCore实现了一种解决方法。

var ticket = LegacyOAuthSecurityTokenHelper.GetTicket(token, new LegacyTokenAuthenticationOptions
    {
        DecryptionKey = "machineKey-DecryptionKey",
        ValidationKey = "machineKey-ValidationKey",
        EncryptionMethod = EncryptionMethod.AES, // Default AES
        ValidationMethod = ValidationMethod.HMACSHA256 // Default HMACSHA256
    }));

// Authenticate your user with ticket.Identity.Claims!
Run Code Online (Sandbox Code Playgroud)