使用 Owin 会话 cookie 身份验证时如何为“AcquireTokenOnBehalfOf()”创建 UserAssertion

use*_*749 5 .net authentication cookies oauth owin

我正在开发一对简单的 .NET 应用程序,用户可以在其中订阅自动报告的分发列表。我需要前端应用程序在向管理发行版的后端应用程序发出请求时能够代表用户进行身份验证。

我拥有应用程序权限等,所有这些都在 Azure 中正确设置,但 AcquireTokenOnBehalfOf() 调用需要 UserAssertion 对象。我见过的所有示例都传递一个 JWT 令牌,它们可以轻松地从 BootstrapContext 或其令牌所在的位置提取到 UserAssertion 构造函数中,如下所示:

var userAssertion = new UserAssertion(bootstrapContext?.Token);
Run Code Online (Sandbox Code Playgroud)

或者像这样:

 var userAssertion = new UserAssertion(bootstrapContext?.Token, 
                                       "urn: ietf:params:oauth: grant - type:jwt - bearer",
                                        userName);
Run Code Online (Sandbox Code Playgroud)

问题是我没有使用令牌身份验证;我正在通过 Owin 使用会话身份验证。

我的问题是是否可以使用 OwinContext 中某处存储的信息来HttpContext.GetOwinContext().Authentication.User创建或伪造令牌或以其他方式手动组装 UserAssertion?或者是否无法使用会话 cookie 身份验证进行 OAuth?