WS-Federation Azure AD On-Behalf-Of流程

时间:2018-02-21 20:13:46

标签: azure asp.net-core oauth-2.0 azure-active-directory ws-federation

我在Azure AD中使用WS-Federation,如下面的代码所示。我也使用cookie身份验证。

            services.AddAuthentication(sharedOptions =>
            {
                sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                sharedOptions.DefaultChallengeScheme = WsFederationDefaults.AuthenticationScheme;
            })
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, authenticationOptions =>
            {
                authenticationOptions.Cookie.Name = "access_token";
            })
            .AddWsFederation(config =>
            {
                config.Wtrealm = options.Realm;
                config.MetadataAddress = options.MetadataAddress;
                config.Events.OnAuthenticationFailed = (context) =>
                {
                    context.HandleResponse();
                    context.Response.Redirect(options.FailedAuthRedirectUrl);
                    return Task.CompletedTask;
                };
                config.SaveTokens = true;
            });

我遇到的问题是为了实现代表流,我想根据Web应用程序使用的当前令牌为另一个Web API服务生成一个新令牌。我跟随https://dzimchuk.net/using-the-on-behalf-of-flow-in-your-aspnet-core-services-protected-by-azure-ad/

我需要原始令牌来创建UserAssertion:

 if (HttpContext.User.Identity.IsAuthenticated)
        {
             var originalToken = await httpContextAccessor.HttpContext.Authentication.GetTokenAsync("access_token");
        }

originalToken总是为null但是,我尝试了很多Scheme名称和cookie名称的组合。我可以看到请求中有一个名为" access_token"的cookie。这种方法永远不会与WS-Federation和cookie一起使用吗?

0 个答案:

没有答案