使用ASP.NET Azure WebApp和托管服务标识进行身份验证

时间:2018-05-23 15:56:42

标签: asp.net azure azure-active-directory azure-web-app-service

我有一个Azure Web App,可以使用Azure AD应用程序对用户进行身份验证。

       app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = ClientId,
                Authority = Authority,
                PostLogoutRedirectUri = PostLogoutRedirectUri,

                Notifications = new OpenIdConnectAuthenticationNotifications()
                {
                    // If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.
                    AuthorizationCodeReceived = (context) =>
                    {
                        var code = context.Code;
                        var credential = new ClientCredential(ClientId, AppKey);
                        var signedInUserId = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
                        var token = authenticationService.GetADALTokenCache(signedInUserId);
                        var authContext = new AuthenticationContext(Authority, token);

                        return authContext.AcquireTokenByAuthorizationCodeAsync(
                            code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, GraphResourceId);
                    }
                }

使用我传入的配置可以100%正常工作。我现在添加了一个托管服务标识,以便我可以授予对Web应用程序的其他资源(例如Key Vault)的访问权限。甜。

这使我用于OpenIdConnectAuthentication的应用程序标识感到多余。我是否能够使用托管服务标识进行身份验证而不是拥有两个帐户 - 一个用于MSI,另一个用于用户身份验证?

使用MSI时,我不想从配置中提供ClientID和AppKey,我只想让它一直流过,使用我的帐户进行本地开发(并在localhost上运行)和MSI部署后分配给Web应用程序。

我正在使用完整的.Net Framework(即Not Core)

0 个答案:

没有答案