我有Identity Server 4的本地实例,我正在尝试按照本指南创建Javascript客户端。这使用oidc-client-js库,而我使用的是登录弹出窗口方法,因此我的登录事件处理程序如下所示:
signin(e) {
e.preventDefault();
this.oidcUserMgr.signinPopup({state:'some data'}).then(function(user) {
console.log("signed in", user.profile);
}).catch(function(err) {
console.log(err);
});
}
Run Code Online (Sandbox Code Playgroud)
身份验证似乎可以正常工作-我已重定向到接受客户端请求,对我的登录进行身份验证并将我返回到客户端应用程序的Identity Server。但是,文档说user.profile上述代码中的对象应包含用户声明,但没有。这是use.profile我得到的:
该sub属性是刚刚通过身份验证的用户的正确ID。但我的身份服务器也发出响应其他领域我的客户要求(索赔profile和email),所以我应该看到的索赔,如name,preferred_username,email等)。我可以观察到IProfileService在IS4中调试我的实现时发出的这些声明。此外,如果我使用access_token带有用户对象的return来向本地运行的另一个API(ASP.NET Web API)发出请求,则可以在this.User.Claims以下位置看到这些声明:
那么如何在我的Javascript代码中掌握这些主张呢?
javascript asp.net openid-connect identityserver4 oidc-client-js
appsettings.json我在我的...中定义了以下内容
{
"Environments": [
{
"Name": "One",
"CloudServices": [
"name1",
"name2"
]
},
{
"Name": "Two",
"CloudServices": [
"name3",
"name4"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
...以及以下强类型模型:
public class EnvironmentModel
{
public string Name { get; set; }
public string[] CloudServices { get; set; }
}
public class EnvironmentsConfig
{
public EnvironmentModel[] Environments { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我希望我可以Startup像这样绑定它:
services.Configure<EnvironmentsConfig>(Configuration.GetSection("Environments"));
Run Code Online (Sandbox Code Playgroud)
但是,当注入我的控制器时,IOptions<EnvironmentsConfig>该值为空。是否可以像这样绑定强类型数组?如果不是,推荐的方法是什么?部署之间的环境数量可能有所不同,因此我需要一个数组。
我们有一个带有这个 appsettings.json 的 ASP.NET Core Web 应用程序:
{
"Subscriptions": [
{
"Name": "Production",
"PublishSettings": "<PublishData>SECRET</PublishData>",
"Environments": [
{
"Name": "Prod",
"DeploymentServiceNames": [
"api1",
"api2",
"api3"
]
}
]
},
{
"Name": "Test",
"PublishSettings": "<PublishData>SECRET</PublishData>",
"Environments": [
{
"Name": "Test1",
"DeploymentServiceNames": [
"api1",
"api2"
]
},
{
"Name": "Test2",
"DeploymentServiceNames": [
"api1",
"api2"
]
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
这些PublishSettings值是秘密的,所以我希望在我的本地用户机密文件和我的部署的环境变量中使用这些值。但是,因为Subscriptions是一个数组,我不确定如何。我不是特别想交换整个Subscriptions部分。有没有办法为这样一个数组中的每个项目交换一个属性,也许是通过在强类型订阅模型上定义一个键属性?
我有一个使用StructureMap的ASP.NET MVC应用程序.
我创建了一个名为SecurityContext的服务,它具有静态Current属性.简化版本如下所示:
public class SecurityContext : ISecurityContext
{
public bool MyProperty { get; private set; }
public static SecurityContext Current
{
get
{
return new SecurityContext() { MyProperty = true };
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已经在我的StructureMap注册表中将其连接起来,如下所示:
For<ISecurityContext>().Use(() => SecurityContext.Current);
Run Code Online (Sandbox Code Playgroud)
我对Use方法的Linq表达式重载的理解是返回的具体对象对于整个HTTP请求范围是相同的.
但是,我已经设置了一个测试用例,其中我的上下文接口被注入两个位置,一次在控制器的构造函数中,并再次使用SetterProperty我的视图继承自的基类中的属性.
在调试时,我观察Current静态方法被击中两次,所以我的假设是错误的.谁能纠正我在这里做的事情?我想要这个请求范围的原因是因为我正在从数据库中将某些数据加载到我的上下文类中,所以我不希望这对于给定的页面加载多次发生.
提前致谢.
我们有一个Kentico实例,它将媒体文件存储在Azure blob存储中.上传SVG类型的图像时,它使用默认内容类型"application/octet-stream"存储它们.这意味着它们无法在浏览器中正确显示.修复方法是使用正确的内容类型"image/svg + xml".有谁知道是否可以强制Kentico将此内容类型用于SVG文件?
我意识到这可以在使用Powershell上传后完成,但这是一个不适合推出内容编辑器的技术步骤.
我有验证登录表单(带有“记住我”的选项)并验证用户身份(如果有效)的代码。然后,我设置表单身份验证cookie并重定向。
auth cookie设置如下,persistent参数是true用户是否选择了“记住我”。
FormsAuthentication.SetAuthCookie(response.UserObject.UserName, persistent);
Response.Redirect(url);
Run Code Online (Sandbox Code Playgroud)
我们已经在各种浏览器中对此进行了测试,并且总体来说还不错。但是,在Firefox中,.ASPXFORMSAUTHcookie始终是会话cookie,即使关闭了persistent以上参数,该cookie也会在关闭浏览器时过期true。
我正在测试的Firefox版本是55.0.3(32位)。这是一个已知的错误?还是有其他原因导致Firefox不允许我设置持久性Cookie?难道它不再接受永久性cookie作为302重定向响应的一部分吗?
我有两个接口,IExampleClient和IServiceUsingClient. 每个都有两个实现。它们在 Castle Windsor 安装程序中注册如下:
container.Register(Component.For<IExampleClient>()
.ImplementedBy<FirstClient>()
.LifestyleTransient()
.Named("FirstClient"));
container.Register(Component.For<IExampleClient>()
.ImplementedBy<SecondClient>()
.LifestyleTransient()
.Named("SecondClient"));
container.Register(Component.For<IServiceUsingClient>()
.ImplementedBy<FirstService>()
.LifestyleTransient()
.Named("FirstService")
.DependsOn(Dependency.OnComponent(typeof(IExampleClient), "FirstClient")));
container.Register(Component.For<IServiceUsingClient>()
.ImplementedBy<SecondService>()
.LifestyleTransient()
.Named("SecondService")
.DependsOn(Dependency.OnComponent(typeof(IExampleClient), "SecondClient")));
Run Code Online (Sandbox Code Playgroud)
请参阅 IServiceUsingClient 的两种实现都依赖于 IExampleClient 的不同实现。为了完成这项工作,我使用了该DependsOn方法来确保使用特定的命名注册。
我现在有一组组件测试,我想在其中模拟 IExampleClient 实现。通常我会通过使用该IsDefault()选项覆盖注册来做到这一点。但是,因为这些是命名注册,所以我不能这样做。Castle 抱怨说已经有一个使用提供的名称进行注册。但是,如果我使用不同的名称注册,那么我IServiceUsingClient将获得真正的实现,而不是我的模拟。
我希望我忽略了一种可以实现我的目标的技术,而不必在我的测试中覆盖整个依赖链。有任何想法吗?
我已经创建了一些用于部署 Azure 指标警报规则的 ARM 模板,但我现在需要部署日志警报规则(即基于 Application Insights 查询而不是平台指标的规则)。
我已按照此处的示例编写了模板脚本(这表明我需要创建类型为 的资源Microsoft.Insights/scheduledQueryRules),并使用 Azure 门户的模板部署服务进行部署,如此处所述。
Azure 报告部署成功,活动日志向我提供部署结果,包括我的新资源的 ID,例如/subscriptions/[subscription-id]/resourcegroups/[alerts-resource-group]/providers/Microsoft.Insights/scheduledQueryRules/Custom errors spike alert。
但是,当我导航到订阅 [subscription-id] 中的“监视器”边栏选项卡并按资源组 [alerts-resource-group] 进行筛选时,我没有看到新警报。
作为一项健全性检查,我使用针对相同 App Insights 资源的相同流程创建了一个指标警报,并且该警报确实显示在“监视器”边栏选项卡中。
我想我的问题是,我是否误解了基于日志的警报规则?例如,Azure“资源”类型是否Microsoft.Insights/scheduledQueryRules等同于“监视/警报/管理警报规则”中信号类型“日志搜索”的警报规则?我确信我的模板是正确的,因为它通过了验证并成功完成。但我对警报规则的结局感到困惑!
我应该提到的一件事是,我在与 App Insights 实例本身不同的资源组中创建警报规则,但指标警报也是如此,因此假设这并不重要。
我有一个使用模板化作业的管道,如下所示:
- template: '/pipeline/templates/jobs/DeployInfraToRegion.yml@devops'
parameters:
...
Run Code Online (Sandbox Code Playgroud)
此作业将编译的 Bicep 模板部署到 Azure。该模板创建一个 KeyVault 并输出其名称,如下所示:
output sqlSecretsKeyVaultName string = keyvault.outputs.keyVaultName
Run Code Online (Sandbox Code Playgroud)
上面的模板包含一个名为DeployInfrastruct的作业:
jobs:
- deployment: DeployInfrastructure
displayName: Deploy Infrastructure
variables:
...
Run Code Online (Sandbox Code Playgroud)
它运行一个最终任务,该任务获取所有输出并将它们设置为管道变量:
- task: PowerShell@2
name: SetArmOutputsForRegion
displayName: "Set Arm outputs as variables"
inputs:
targetType: inline
pwsh: true
errorActionPreference: stop
script: |
$armOutputString = '$(${{ parameters.armOutputVariable }})'
$armOutputObj = $armOutputString | convertfrom-json
$armOutputObj.PSObject.Properties | ForEach-Object {
$type = ($_.value.type).ToLower()
$key = $_.name
$value = $_.value.value
if ($type -eq "securestring") {
Write-Host "##vso[task.setvariable …Run Code Online (Sandbox Code Playgroud) asp.net ×6
c# ×4
asp.net-core ×3
azure ×3
.net-core ×1
azure-devops ×1
cookies ×1
firefox ×1
javascript ×1
kentico ×1
structuremap ×1
svg ×1
yaml ×1