请帮助我了解来自 ASP netcore 应用程序和 netcore Kestrel 托管应用程序的 JWT 令牌验证之间的区别。
有两个应用程序使用如下源代码验证令牌:
public static IServiceCollection AddJwtToken(this IServiceCollection services, OAuthConfig config)
{
services.AddMvc();
services.AddAuthorization();
Logger.DebugFormat("AddJwtBearer authority:{0} audience:{1}", config.GetAuthority(), config.Resource);
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options => new JwtBearerOptions
{
Authority = config.GetAuthority(),
Audience = config.Resource,
});
return services;
}
Run Code Online (Sandbox Code Playgroud)
它非常简单,如果从 asp net core 2.2 应用程序验证令牌,它就可以很好地工作
// in the asp.net core
var builder = WebHost.CreateDefaultBuilder(args);
builder
.UseStartup<Startup>()
.ConfigureKestrel(_ => _.ConfigureEndpoints())
.UseSerilog();
Run Code Online (Sandbox Code Playgroud)
还有另一个应用程序(控制台)使用 UseKestrel
//in the console app
var builder = WebHost.CreateDefaultBuilder()
.UseNLog()
.UseKestrel(_ => _.ConfigureEndpoints())
.UseStartup<Startup>();
Run Code Online (Sandbox Code Playgroud)
唯一的一个显着区别是UseKestrel …
尝试将 Azure AD 用作具有IdentityModel包的 OpenID 提供程序
但问题是它会产生错误的端点配置
var client = new HttpClient();
const string identityUrl = "https://login.microsoftonline.com/00edae13-e792-4bc1-92ef-92a02ec1d939/v2.0";
const string restUrl = "https://localhost:44321";
var disco = await client.GetDiscoveryDocumentAsync(identityUrl);
if (disco.IsError)
{
Console.WriteLine(disco.Error);
return;
}
Run Code Online (Sandbox Code Playgroud)
返回错误
端点属于不同的权限: https://login.microsoftonline.com/00edae13-e792-4bc1-92ef-92a02ec1d939/oauth2/v2.0/authorize
openid 配置输出是
{"authorization_endpoint":"https://login.microsoftonline.com/00edae13-e792-4bc1-92ef-92a02ec1d939/oauth2/v2.0/authorize",
"token_endpoint":"https://login.microsoftonline.com/00edae13-e792-4bc1-92ef-92a02ec1d939/oauth2/v2.0/token" ... }
Run Code Online (Sandbox Code Playgroud)
oauth2添加在 tenatID 和版本之间。我想这就是 openid 元数据验证失败的原因。
是否可以将 AzureAD 配置为返回 openid-configuration 的正确元数据?
问候
我有存储在网络上的X509证书.我可以从远程Windows证书库中读取链.我需要签署一些数据并在签名中包含链,以便以后验证它.
问题是我找不到将证书链放到CsmSigner的方法.我已经读过它从构造函数参数获取证书并尝试使用X509Chain.Build构建一个链.它忽略了证书列表值并且(显然)失败,因为在本地Windows证书库中找不到证书.
请在下面找到我的测试代码(仅当证书本地保存到Windows证书库时才有效)
protected byte[] SignWithSystem(byte[] data, X509Certificate2 cert, X509Certificate[] chain)
{
ContentInfo contentInfo = new ContentInfo(data);
SignedCms signedCms = new SignedCms(contentInfo, true);
CmsSigner cmsSigner = new CmsSigner(cert);
cmsSigner.DigestAlgorithm = new Oid("2.16.840.1.101.3.4.2.1"); //sha256
cmsSigner.IncludeOption = X509IncludeOption.WholeChain;
if (chain != null)
{
//adding cert chain to signer
cmsSigner.Certificates.AddRange(chain);
signedCms.Certificates.AddRange(chain);
}
signedCms.ComputeSignature(cmsSigner); //fails here with System.Security.Cryptography.CryptographicException : A certificate chain could not be built to a trusted root authority.
byte[] signedPkcs = signedCms.Encode();
return signedPkcs;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法让它无需上传证书到本地商店?我应该使用任何替代签名者吗?
我可以尝试将证书上传到商店,但问题是这样
我必须添加和删除证书(必须授予权限)
有几个进程应用签名,因此必须添加跨进程同步.
这不是我想做的.
亲爱
请帮我恢复延迟(和持久)的工作流程.
我正在尝试检查自托管工作流程存储是否存在任何延迟且可以恢复的实例.出于测试目的,我创建了延迟的虚拟活动,并且在延迟时间内持续存在.
一般恢复过程看起来像:
get WF definition
configure sql instance store
call WaitForEvents
is there event with HasRunnableWorkflowEvent.Value name and if it is
create WorkflowApplication object and execute LoadRunnableInstance method
Run Code Online (Sandbox Code Playgroud)
如果商店被称为商店关闭created|initialized,它的工作正常WaitForEvents.在这种情况下,存储从持久数据库中读取所有可用的工作流,如果没有workflows可用的恢复,则抛出超时异常.
如果创建了存储并且仅为WaitForEvents(同样的事情发生BeginWaitForEvents)启动循环,则会出现问题.在这种情况下,它会workflows从DB(使用适当的ID)读取所有可用的内容,但之后timeout exception它将再读取一个实例(我确切地知道有多少实例workflows可以恢复,因为使用了单独的测试database).但没有阅读和throws InstanceNotReadyException.在catch我正在检查workflowApplication.Id,但它之前没有保存我的测试.
我试图在新的(空)持久数据库上运行,结果是一样的:(
此代码失败:
using (var storeWrapper = new StoreWrapper(wf, connStr))
for (int q = 0; q < 5; q++)
{
var …Run Code Online (Sandbox Code Playgroud) 当我使用以下命令运行 ASP.Net Core 应用程序时,请帮助我指定配置文件名称dotnet WebApplicationLaunchProfile.dll
我使用这个简短的形式只是为了能够在 VS 之外运行该项目并检查它是如何工作的。
我知道我可以使用它dotnet run --launch-profile testProfileName,但需要.csproj源.cs文件可用。我想避免复制源代码文件并使用编译的程序集。我的流程是:
dotnet buildbin\Debug文件夹内容)复制到单独的文件夹dotnet WebApplicationLaunchProfile.dll使用表单启动 dll 以使用正确的配置文件名称然而问题是
使用 dotnet run 启动应用程序时,将使用第一个带有“commandName”的配置文件:“Project”
如果使用命令执行项目,则不应用文档中的规则dotnet dll。很明显,由于我没有使用该命令,因此不应应用它dotnet run。
不过我想以某种方式指定配置文件名称。
我已经从 VS 模板创建了新的 ASP.Net Core 项目并更新了文件,launchSettings.json如下所示:
{
"$schema": "http://json.schemastore.org/launchsettings.json",
...
"profiles": {
...
"WebApplicationLaunchProfile": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:4430;http://localhost:8080",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已经调整了该profiles:WebApplicationLaunchProfile:applicationUrl …
请帮助我长按图标按钮检测。
我正在尝试获取一个图标按钮,如果点击该图标按钮,则数量值将更改 1,长按则将数量值更改为 10。问题是,不幸的是,Flutter 2.12 中没有可用的长按事件处理程序IconButton。
所以我只使用了Icon里面的Container如下
GestureDetector(
child: Container(
child: const Icon(
Icons.add,
),
padding: EdgeInsets.symmetric(vertical: 6.0, horizontal: 18.0),
),
onTap: () {
increment(1);
},
onLongPressStart: (_) async {
startPressing(() => increment(10));
},
onLongPressCancel: () {
cancelPress();
},
onLongPressEnd: (_) {
cancelPress();
},
),
Run Code Online (Sandbox Code Playgroud)
它可以工作,但问题是按压区域非常小,在移动设备上找到按压点很不舒服。
我尝试将图标大小增加到 48 但结果很糟糕,图标大得不自然
const Icon(
Icons.add,
size: 48,
),
Run Code Online (Sandbox Code Playgroud)
对我来说看起来不错的设计是将GestureDetector(长按)与IconButton(和 onPressed 用于单击检测)一起使用:
GestureDetector(
child: IconButton(
onPressed: () => decrement(1),
icon: const Icon(
Icons.remove,
), …Run Code Online (Sandbox Code Playgroud) 请帮助我格式化使用文件记录器记录的异常我希望在内部异常(如果有)之间使用新行分隔符记录异常,异常类型用某种特殊类型的符号包围,例如[ArgumentException]使其与错误文本不同,和用于 tab 的例外只是为了便于阅读堆栈跟踪
我检查了最新的 NLog 4.4.12 包,但问题是参数化默认布局以获得类似的东西并不容易
2017-10-04 15:13:22.5823 NLogTest.Program starting
2017-10-04 15:13:22.5823 NLogTest.Program failed to start NLogTest
[ArgumentException] bad try
at NLogTest.Classes.UnitOfWork.tryException() in d:\projects\NLogTest\Program.cs:line 62
at NLogTest.Program.Main(String[] args) in d:\projects\NLogTest\Program.cs:line 19
[ArgumentException] outer exception
at NLogTest.Classes.UnitOfWork.outerException() in d:\projects\NLogTest\Program.cs:line 49
at NLogTest.Classes.UnitOfWork.tryException() in d:\projects\NLogTest\Program.cs:line 57
[KeyNotFoundException] innerException
at NLogTest.Classes.UnitOfWork.innerException() in d:\projects\NLogTest\Program.cs:line 38
at NLogTest.Classes.UnitOfWork.outerException() in d:\projects\NLogTest\Program.cs:line 45
2017-10-04 15:13:22.5823 NLogTest.Program the end
Run Code Online (Sandbox Code Playgroud)
这是我想获取的异常文件日志。我试过像这样的布局
layout="${longdate} ${logger} ${message}${onexception:${newline}${exception:format=tostring}}"
Run Code Online (Sandbox Code Playgroud)
它使用标准的 tostring 异常方法,但结果不一样。我不喜欢那个
2017-10-04 15:28:52.6881 NLogTest.Program failed to start NLogTest
System.ArgumentException: bad …Run Code Online (Sandbox Code Playgroud)