且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Graph API-使用.Net Core 3.1添加架构扩展

更新时间:2023-02-15 12:51:29

我已经测试了您的代码.它对于Azure AD正常工作,但出现错误代码:Service_InternalServerError \ r \ n消息:遇到内部服务器错误.\ r \ n \ r \ n内部错误\ r \ n 对于Azure AD B2C.>

我认为Microsoft Graph API article 说,Azure AD B2C中的自定义属性使用Microsoft.Graph.Beta

UPDATE - Graph API init

private async Task<GraphServiceClient> InitGraphClientWithUserAndPassword()
{
    try
    {
        IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
            .Create(_appClientId.ToString())
            .WithTenantId(_tenantId.ToString())
            .Build();

        UsernamePasswordProvider authProvider = new UsernamePasswordProvider(publicClientApplication); // scopes

        GraphServiceClient graphClient = new GraphServiceClient(authProvider);

        SecureString securePass = new NetworkCredential("", _password).SecurePassword;
        User me = await graphClient.Me.Request()
            .WithUsernamePassword(_userEmail, securePass)
            .GetAsync();

        return graphClient;
    }
    catch (Exception ex)
    {
        const string ERR_MSG = "Could not create GraphAPI client";
        _logger.LogError(ex, ERR_MSG);
        throw new IlgGraphApiException(ERR_MSG, ex);
    }
}

I have tested your code. It works fine for Azure AD but gets error Code: Service_InternalServerError\r\nMessage: Encountered an internal server error.\r\n\r\nInner error\r\n for Azure AD B2C.

I don't think Microsoft Graph API Create schemaExtension is supported for Azure AD B2C currently.

As this article says, Custom attributes in Azure AD B2C use Azure AD Graph API Directory Schema Extensions. Support for newer Microsoft Graph API for querying Azure AD B2C tenant is still under development.