代码之家  ›  专栏  ›  技术社区  ›  Murray Foxcroft

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

  •  2
  • Murray Foxcroft  · 技术社区  · 6 年前

    我有一个Azure Web应用程序,它使用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应用程序的其他资源(如密钥库)的访问权限。太好了。

    这使我用于OpenIdConnectAuthentication的应用程序标识感到多余。我是否可以只使用托管服务标识来进行身份验证,而不使用两个帐户—一个用于MSI,一个用于用户身份验证?

    在使用MSI时,我不想从config中提供ClientID和AppKey,我只想让它一直通过,使用我的本地dev帐户(在localhost上运行)和部署时分配给web应用的MSI。

    我正在使用完整的.Net框架(即非核心)

    0 回复  |  直到 6 年前