相关疑难解决方法(0)

JWT on .NET Core 2.0

我一直在冒险让JWT在DotNet核心2.0上工作(现在到达最终版本).有大量的文档,但是所有的示例代码似乎都在使用已弃用的API并且刚刚进入Core,它确实令人眼花缭乱地想出它应该如何实现.我尝试使用Jose,但应用程序.不推荐使用UseJwtBearerAuthentication,并且没有关于下一步操作的文档.

有没有人有一个使用dotnet core 2.0的开源项目,它可以简单地从授权头解析JWT并允许我授权HS256编码的JWT令牌?

类下面不抛出任何异常,但没有请求授权,和我没有得到任何指示,为什么他们是未经授权的.响应是空的401,所以对我来说,表明没有异常,但秘密不匹配.

奇怪的是我的令牌是用HS256算法加密的,但是我没有看到任何指示器要求它强制它在任何地方使用该算法.

这是我到目前为止的课程:

using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Net.Http.Headers;
using Newtonsoft.Json.Linq;
using Microsoft.IdentityModel.Tokens;
using System.Text;

namespace Site.Authorization
{
    public static class SiteAuthorizationExtensions
    {
        public static IServiceCollection AddSiteAuthorization(this IServiceCollection services)
        {
            var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("SECRET_KEY"));

            var tokenValidationParameters = new TokenValidationParameters
            {
                // The signing key must match!
                ValidateIssuerSigningKey = true,
                ValidateAudience = false,
                ValidateIssuer = false, …
Run Code Online (Sandbox Code Playgroud)

c# jwt .net-core jose

79
推荐指数
4
解决办法
5万
查看次数

System.InvalidOperationException:IDX20803:无法从 .NET 5 的“System.String”获取配置

我一直在实现 IdentityServer4 来为我的 React 应用程序提供授权。我在本地开发环境中运行此功能,但在部署到 Windows Server 2016 中的 IIS 后遇到问题。我能够通过 /connect/token 端点生成访问令牌,但是当我尝试使用以下命令访问受保护的 API 时令牌我得到以下异常:

System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'System.String'.
 ---> System.IO.IOException: IDX20804: Unable to retrieve document from: 'System.String'.
 ---> System.Net.Http.HttpRequestException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (dev-drydata-auth.universal-compliance.com:443)
 ---> System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a …
Run Code Online (Sandbox Code Playgroud)

jwt asp.net-web-api identityserver4 .net-5

20
推荐指数
2
解决办法
7万
查看次数

任务被取消了

我正在尝试在同一个启动中共同主持identityserver3和web api(用于使用Bearer令牌的用户管理).但是我收到以下错误:任务被取消了.当尝试调用http://identity_local/core/.well-known/openid-configuration(identity_local指向localhost)时,启动时会发生任务取消.

我的创业公司如下:

app.Map("/core", idsrvApp =>
        {
            var factory = new IdentityServerServiceFactory();
            factory.UserService = new IdentityServer3.Core.Configuration.Registration<IUserService, UserService>();
            factory.ScopeStore = new IdentityServer3.Core.Configuration.Registration<IScopeStore>(resolver => scopeStore);
            var options = new IdentityServerOptions
            {
                SigningCertificate = Certificate.Load(),
                IssuerUri = "http://identity_local/core",
                PublicOrigin = "http://identity_local",
                RequireSsl = false, //for now
                Factory = factory,
            };

            idsrvApp.UseIdentityServer(options);
        });

        app.Map("/admin", adminApp =>
        {
            adminApp.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                Authority = "http://identity_local/core",
                IssuerName = "identity_local",
                ValidationMode = ValidationMode.Local,
                RequiredScopes = new[] { "api", "roles" }
            });

            adminApp.UseResourceAuthorization(new AuthorisationManager());

            var config = …
Run Code Online (Sandbox Code Playgroud)

identityserver3

2
推荐指数
1
解决办法
1446
查看次数