基本上,同样的问题我要求默认的内容类型,但这次是Headers:Microsoft是否为标准的HTTP标题名称创建了一个充满常量的类,还是我必须自己编写?
我有一个Web应用程序,它使用隐式客户端向Identity Server 4验证用户身份.我需要此用户的访问令牌,以便我可以调用另一个API.
要明确:
Web应用程序根据身份服务器对用户进行身份验证.一旦对它们进行了身份验证,我们就会使用承载令牌来访问API.
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddAuthentication(options =>
{
options.DefaultScheme = "cookie";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("cookie")
.AddOpenIdConnect("oidc", options =>
{
options.Authority = Configuration["ServiceSettings:IdentityServerEndpoint"];
options.ClientId = "f91ece52-81cf-4b7b-a296-26356f50841f";
options.SignInScheme = "cookie";
});
Run Code Online (Sandbox Code Playgroud)
用户正在进行身份验证,我可以访问下面的控制器.我需要为此用户提供访问令牌,以便我可以向另一个API发出请求.
[Authorize]
public async Task<IActionResult> Index(int clientId, string error)
{
ViewData["Title"] = "Secrets";
if (User.Identity.IsAuthenticated)
{
// All of the below attempts result in either null or empty array
var attempt1 = Request.Headers["Authorization"];
var attempt2 = await HttpContext.GetTokenAsync("access_token");
var attempt3 …
Run Code Online (Sandbox Code Playgroud)