小编nwa*_*yve的帖子

如何使用Cognito联合身份验证配置MVC 5应用程序

我试图通过OWIN中间件在Amazon Cognito中使用已配置的SAML Provider进行身份验证的MVC 5应用程序。

在我的启动课程中,我有:

app.Use(typeof(AuthenticationMiddleware));
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    LoginPath = new PathString("/Account/Login"),
    Provider = new CookieAuthenticationProvider
    {
        OnValidateIdentity = MyCustomValidateIdentity
    },
    SlidingExpiration = true,
    ExpireTimeSpan = TimeSpan.FromMinutes(timespan)
});

var config = ConfigHelper.CognitoConfigSection;
var signingCert = new X509Certificate2(Encoding.ASCII.GetBytes(config.cert));
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
    AuthenticationType = "Cognito",
    AuthenticationMode = AuthenticationMode.Passive,
    Authority = $"https://cognito-idp.{config.Region}.amazonaws.com/{config.UserPoolId}",
    ResponseType = "code",
    ClientId = config.UserpoolClientId,
    ClientSecret = config.UserpoolClientSecret,
    Scope = String.Join(" ", "openid", "profile", "email"),
    MetadataAddress = $"https://cognito-idp.{config.Region}.amazonaws.com/{config.UserPoolId}/.well-known/openid-configuration",
    RedirectUri = "http://localhost:12345",
    TokenValidationParameters = new TokenValidationParameters …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services owin asp.net-mvc-5 amazon-cognito

5
推荐指数
0
解决办法
386
查看次数