首页 文章

如何仅使用Microsoft个人帐户在Microsoft Graph中进行身份验证?

提问于
浏览
0

According to documentation,Microsoft Graph仅支持Azure AD v2.0和Azure AD中的令牌:

Microsoft Graph支持两种身份验证提供程序:要使用个人Microsoft帐户(如live.com或outlook.com帐户)对用户进行身份验证,请使用Azure Active Directory(Azure AD)v2.0 endpoints . 要使用企业(即工作或学校)帐户对用户进行身份验证,请使用Azure AD .

但是,Azure AD v2.0是支持两种Microsoft帐户类型的新 endpoints :个人(以前的真实帐户)和工作/学校(经典的Azure AD帐户) . 目前还不清楚,如何限制个人账户的授权 .

Azure AD仅支持工作/学校帐户 .

那么,如果我想让我的应用只使用个人账户,该怎么办呢?如何仅使用Microsoft个人帐户在Microsoft Graph中进行身份验证(禁止用户使用工作/学校帐户)?

P.S . :如果重要的话,我在我的应用程序中使用MSAL进行身份验证 .

1 回答

  • 2

    根据Azure AD v2.0的文档,如果您只想支持 Microsoft Accounts ,您要使用的 endpoints 是 https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize . 这里的关键是 consumers ,这将确保您的用户只能获得使用Microsoft帐户进行身份验证的选项 .

    如果我要采取Github example of MSAL,你所做的改变是Startup_Auth.cs

    app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    // The `Authority` represents the v2.0 endpoint - https://login.microsoftonline.com/consumers/v2.0
                    // The `Scope` describes the initial permissions that your app will need.  See https://azure.microsoft.com/documentation/articles/active-directory-v2-scopes/                    
                    ClientId = clientId,
                    Authority = String.Format(CultureInfo.InvariantCulture, aadInstance, "consumers", "/v2.0"),
                    RedirectUri = redirectUri,                    
                    Scope = "openid email profile offline_access Mail.Read",
                    PostLogoutRedirectUri = redirectUri,
                    TokenValidationParameters = new TokenValidationParameters
    

相关问题