通过Powershell进行Dotnet Core Saml2身份验证

时间:2020-06-19 13:01:42

标签: powershell asp.net-core .net-core sustainsys-saml2

我有一个使用Sustainsys Saml2软件包进行身份验证的dotnet核心应用程序。通过浏览器完成访问应用程序的工作。用户请求该应用程序,如果未通过身份验证,则将其重定向到联合身份验证登录页面。登录后,它们将返回到应用程序。该应用程序具有一个我想通过Powershell访问的API,但是在通过身份验证后进入该应用程序时遇到了问题。我的IdP有一个API,我可以使用Invoke-RestMethod来调用该API,该API返回身份验证cookie,并将其作为命令的一部分存储在会话变量中。接下来,我将对我的api加上另一个Invoke-RestMethod并添加会话。问题是我的应用程序没有看到我的会话已通过身份验证,而是将我重定向到联合身份验证登录页面,在那里我看到我已通过身份验证并将我发送回应用程序,并且重复该循环。

重定向上的位置标头是https://..../error?access_denied,我认为当应用程序尝试调用await AuthenticationManager.GetExternalLoginInfoAsync()时已设置该标头。在“启动”中的.addSaml2(...调用中,我在“身份提供程序”选项中将AllowUnsoliciedAuthnResponse设置为true。要在应用程序中进行身份验证,是否需要在应用程序中进行其他配置或在powershell命令中进行其他操作?

Startup.cs
services.addAuthentication(sharedOptions => {
    sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    sharedOptions.DefaultChallengeScheme = Saml2Defaults.Scheme;
    sharedOptions.DefaultForbinScheme = CookieAuthenticationDefaults.AuthenticationScheme;
powershell commands
> invoke-restmethod -Uri "<idp api url>" -SessionVariable login -CertificateThumbprint $cert.thumbprint -Method Post -Body @body
> invoke-restmethod -Uri "<app url>" -WebSession $login -Method Get

0 个答案:

没有答案