ASP.NET Web APP和Web API中的Azure AD Open ID Connect OAuth 2.0无限重定向循环

shubham mahore

ASP.NET Web应用程序可从任何Azure Active Directory(Azure AD)实例登录个人帐户以及工作和学校帐户。

OWIN中间件NuGet软件包

Install-Package Microsoft.Owin.Security.OpenIdConnect
Install-Package Microsoft.Owin.Security.Cookies
Install-Package Microsoft.Owin.Host.SystemWeb

OWIN启动类OWIN中间件使用启动类,该启动类在托管进程初始化时运行。在此快速入门中,位于根文件夹中的startup.cs文件。以下代码显示了此快速入门使用的参数

public void Configuration(IAppBuilder app)
{
    app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

    app.UseCookieAuthentication(new CookieAuthenticationOptions());
    app.UseOpenIdConnectAuthentication(
        new OpenIdConnectAuthenticationOptions
        {
            // Sets the ClientId, authority, RedirectUri as obtained from web.config
            ClientId = clientId,
            Authority = authority,
            RedirectUri = redirectUri,
            // PostLogoutRedirectUri is the page that users will be redirected to after sign-out. In this case, it is using the home page
            PostLogoutRedirectUri = redirectUri,
            Scope = OpenIdConnectScope.OpenIdProfile,
            // ResponseType is set to request the id_token - which contains basic information about the signed-in user
            ResponseType = OpenIdConnectResponseType.IdToken,
            // ValidateIssuer set to false to allow personal and work accounts from any organization to sign in to your application
            // To only allow users from a single organizations, set ValidateIssuer to true and 'tenant' setting in web.config to the tenant name
            // To allow users from only a list of specific organizations, set ValidateIssuer to true and use ValidIssuers parameter
            TokenValidationParameters = new TokenValidationParameters()
            {
                ValidateIssuer = false // Simplification (see note below)
            },
            // OpenIdConnectAuthenticationNotifications configures OWIN to send notification of failed authentications to OnAuthenticationFailed method
            Notifications = new OpenIdConnectAuthenticationNotifications
            {
                AuthenticationFailed = OnAuthenticationFailed
            }
        }
    );
}

ASP.NET MVC / Web API

//You can force a user to sign in by requesting an authentication challenge in your controller:
public void SignIn()
{
    if (!Request.IsAuthenticated)
    {
        HttpContext.GetOwinContext().Authentication.Challenge(
            new AuthenticationProperties{ RedirectUri = "/" },
            OpenIdConnectAuthenticationDefaults.AuthenticationType);
    }
}

ASP.NET Web表单:

 protected void Login_click(object sender, EventArgs e)
        {
            if (!Request.IsAuthenticated)
            {
                HttpContext.Current.GetOwinContext().Authentication.Challenge(
                    new AuthenticationProperties { RedirectUri = "/" },
                    OpenIdConnectAuthenticationDefaults.AuthenticationType);
            }
        }
shubham mahore

该问题已在ASP.NET核心和用于ASP.NET的新版Katana Owin中得到修复。若要解决此问题,您可以升级您的应用程序以使用ASP.NET Core。如果必须继续使用ASP.NET,请执行以下操作:

将应用程序的Microsoft.Owin.Host.SystemWeb软件包至少更新为3.1.0.0版,并修改代码以使用新的cookie管理器类之一,例如以下内容:

app.UseCookieAuthentication(new CookieAuthenticationOptions 
{ 
    AuthenticationType = "Cookies", 
    CookieManager = new Microsoft.Owin.Host.SystemWeb.SystemWebChunkingCookieManager() 
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在ASP.NET核心WEB API中验证Azure AD v2生成的OpenID Connect访问令牌?

来自分类Dev

Windows Azure上托管的ASP.NET Web API 2中的OAUTH2选项

来自分类Dev

Windows Azure上托管的ASP.NET Web API 2中的OAUTH2选项

来自分类Dev

在ASP.NET Web API2 Web服务中实现OAuth访问令牌

来自分类Dev

OAuth(OAuth2)ASP.NET REST Web API(自助主机-Windows服务)实现

来自分类Dev

转换ASP.Net Core中的Open Id Connect声明

来自分类Dev

如何为asp.net Web应用程序获取Google Api OAuth 2刷新令牌?

来自分类Dev

使用 Open ID Connect 访问令牌保护 Web API

来自分类Dev

ASP.Net Web API如何验证OAuth 2.0令牌?

来自分类Dev

ASP.Net Web API如何验证OAuth 2.0令牌?

来自分类Dev

如何在Web App中从Azure AD刷新ID令牌?

来自分类Dev

ASP.NET MVC5 Azure AD Web App模板中的数据库在哪里?

来自分类Dev

在 ASP.NET Core 2 中使用令牌或 Open ID Connect 进行身份验证

来自分类Dev

asp.net Web api 2和jquery帖子

来自分类Dev

OAuth 2.0和Open Id Connect声明问题

来自分类Dev

从iOS中的外部Web浏览器剥离的OAuth2 / Azure AD B2C参数

来自分类Dev

使用Owin在Asp.Net Web Api中同时使用OAuth和基本身份验证

来自分类Dev

ASP.NET WEB API 2中的复杂对象

来自分类Dev

ASP.Net Core 1.0.0-preview2无限重定向循环

来自分类Dev

带有僵尸登录重定向循环的 Azure AD Web 应用程序

来自分类Dev

重定向循环中的Spring Security OAuth2(google)Web应用

来自分类Dev

.Net Web API 2,OWIN和OAuth:范围和角色。有什么区别?

来自分类Dev

使用Google和ASP.NET Core身份的无限登录重定向循环

来自分类Dev

ASP.NET Core Web 应用程序的 Azure AD 身份验证

来自分类Dev

Asp.net Web应用程序和Asp.net Web API2之间的共享会话(Asp.net Web API2托管在访问一种配置的Asp.net Web应用程序下)

来自分类Dev

如何在Asp.net Web Api 2中使用多种Put和Post方法

来自分类Dev

如何在Asp.net Web Api 2中使用多种Put和Post方法

来自分类Dev

AngularJS with .NET Web API: Authentication with AD

来自分类Dev

CORS和ASP.Net Web API

Related 相关文章

  1. 1

    如何在ASP.NET核心WEB API中验证Azure AD v2生成的OpenID Connect访问令牌?

  2. 2

    Windows Azure上托管的ASP.NET Web API 2中的OAUTH2选项

  3. 3

    Windows Azure上托管的ASP.NET Web API 2中的OAUTH2选项

  4. 4

    在ASP.NET Web API2 Web服务中实现OAuth访问令牌

  5. 5

    OAuth(OAuth2)ASP.NET REST Web API(自助主机-Windows服务)实现

  6. 6

    转换ASP.Net Core中的Open Id Connect声明

  7. 7

    如何为asp.net Web应用程序获取Google Api OAuth 2刷新令牌?

  8. 8

    使用 Open ID Connect 访问令牌保护 Web API

  9. 9

    ASP.Net Web API如何验证OAuth 2.0令牌?

  10. 10

    ASP.Net Web API如何验证OAuth 2.0令牌?

  11. 11

    如何在Web App中从Azure AD刷新ID令牌?

  12. 12

    ASP.NET MVC5 Azure AD Web App模板中的数据库在哪里?

  13. 13

    在 ASP.NET Core 2 中使用令牌或 Open ID Connect 进行身份验证

  14. 14

    asp.net Web api 2和jquery帖子

  15. 15

    OAuth 2.0和Open Id Connect声明问题

  16. 16

    从iOS中的外部Web浏览器剥离的OAuth2 / Azure AD B2C参数

  17. 17

    使用Owin在Asp.Net Web Api中同时使用OAuth和基本身份验证

  18. 18

    ASP.NET WEB API 2中的复杂对象

  19. 19

    ASP.Net Core 1.0.0-preview2无限重定向循环

  20. 20

    带有僵尸登录重定向循环的 Azure AD Web 应用程序

  21. 21

    重定向循环中的Spring Security OAuth2(google)Web应用

  22. 22

    .Net Web API 2,OWIN和OAuth:范围和角色。有什么区别?

  23. 23

    使用Google和ASP.NET Core身份的无限登录重定向循环

  24. 24

    ASP.NET Core Web 应用程序的 Azure AD 身份验证

  25. 25

    Asp.net Web应用程序和Asp.net Web API2之间的共享会话(Asp.net Web API2托管在访问一种配置的Asp.net Web应用程序下)

  26. 26

    如何在Asp.net Web Api 2中使用多种Put和Post方法

  27. 27

    如何在Asp.net Web Api 2中使用多种Put和Post方法

  28. 28

    AngularJS with .NET Web API: Authentication with AD

  29. 29

    CORS和ASP.Net Web API

热门标签

归档