【发布时间】:2021-11-10 16:03:54
【问题描述】:
我想修改旧的 ASP.NET WebForms 应用程序以使用 Azure SAML 身份验证。我在 Microsoft 站点上找到了 ASP.NET Core 的 SAML 身份验证示例,并希望修改此代码以适合我的 Web 窗体应用程序启动类。
下面我要修改的代码:
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = "Saml2";
})
.AddSaml2(options =>
{
options.SPOptions.EntityId = new EntityId("https://localhost:44342/Saml2");
options.IdentityProviders.Add(
new IdentityProvider(
new EntityId("https://sts.windows.net/63eb1bcb-f74f-4703-8243-6f73d78ebf52/"), options.SPOptions)
{
MetadataLocation = "https://login.microsoftonline.com/63eb1bcb-f74f-4703-8243-6f73d78ebf52/federationmetadata/2007-06/federationmetadata.xml?appid=9fd05134-d507-479b-a432-580541125356"
});
})
.AddCookie();
此代码使用我的启动类中不可用的“服务”。我现有的代码如下所示:
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
//interactive logon process
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,
//name of the authentication type
AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
//Login path should be below
// LoginPath = new PathString("login"),
//TODO: Enable this to always send and receive cookies in SSL when in production
CookieSecure = CookieSecureOption.Always,
//enable sliding expiration
SlidingExpiration = true,
//Cookie expires in 4 hours
ExpireTimeSpan = TimeSpan.FromTicks(DateTime.Now.AddHours(4).Ticks)
});
Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;
app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
{
MetadataAddress = adfsMetadata,
Wtrealm = realm
});
//This will set ADFS as the default authentication provider
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseStageMarker(PipelineStage.Authenticate);
}
【问题讨论】:
-
只是出于兴趣,您发现了什么 Microsoft SAML 样本?
-
如果我的回复有帮助,请采纳为答案(点击回复旁边的标记选项将其从灰色切换为填写。),请参阅meta.stackexchange.com/questions/5234/…
-
@JasonPan 当然我会的。我正在检查链接。
-
@rbrayb 我没有找到任何适用于 ASP.NET WebForms 的 Microsoft 示例
-
好的 - 当您说“Microsoft 站点上的 SAML 身份验证示例”时,我很困惑,因为没有 Microsoft SAML 示例。这里有一组客户端堆栈 - medium.com/the-new-control-plane/…
标签: asp.net azure asp.net-core webforms saml