相关疑难解决方法(0)

是否有默认HTTP标头的常量?

基本上,同样的问题我要求默认的内容类型,但这次是Headers:Microsoft是否为标准的HTTP标题名称创建了一个充满常量的类,还是我必须自己编写?

asp.net asp.net-mvc http-headers

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

用户已通过身份验证,但访问令牌在哪里?

我有一个Web应用程序,它使用隐式客户端向Identity Server 4验证用户身份.我需要此用户的访问令牌,以便我可以调用另一个API.

要明确:

  1. 我有一个身份服务器.使用Identity Server 4创建.
  2. 我在Asp .net core mvc中创建了有问题的Web应用程序.
  3. 在.net核心中创建的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)

c# asp.net-core-mvc identityserver4

5
推荐指数
1
解决办法
2292
查看次数