Azure AD api graph works with local but does not work on deployment

I tried the graphic code from https://github.com/Azure-Samples/active-directory-dotnet-graphapi-console/tree/master/GraphConsoleAppV3 . He worked on my local system. A window opens on the local machine and a login is requested. But when I deployed the application to the azure web portal, it failed in the place where it receives the token executing Itenent.

"HRESULT E_FAIL error was returned from a call to a COM component" [COMException (0x80004005): HRESULT E_FAIL error was returned from a call to a COM component.]

I think this is a token search from the local system. Is my token search function related to windows or network? Any suggestion for changing the code.

How can I replace this application with deployment work. I think that if we can change ITenantDetail tenantDetail = GetTenantDetailsSync (client, UserModeConstants.TenantId); code that receives information from the user, this should also work on the Internet.

private static ActiveDirectoryClient client;
client = AuthenticationHelper.GetActiveDirectoryClientAsUser();
ITenantDetail tenantDetail = GetTenantDetailsSync(client, UserModeConstants.TenantId);



 public static ITenantDetail GetTenantDetailsSync(IActiveDirectoryClient client, string tenantId)
    {
        ITenantDetail tenant = null;
        try
        {
            IPagedCollection<ITenantDetail> tenantsCollection = client.TenantDetails
                .Where(tenantDetail => tenantDetail.ObjectId.Equals(tenantId)).ExecuteAsync().Result;

            List<ITenantDetail> tenantsList = tenantsCollection.CurrentPage.ToList();

            if (tenantsList.Count > 0)
            {
                tenant = tenantsList.First();
            }
        }
        catch (Exception ex)
        {
        }

        if (tenant == null)
        {
            return null;
        }
        else
        {
            TenantDetail tenantDetail = (TenantDetail)tenant;
            return tenantDetail;
        }
    }



public static ActiveDirectoryClient GetActiveDirectoryClientAsUser()
        {
            Uri servicePointUri = new Uri(GlobalConstants.ResourceUrl);
            Uri serviceRoot = new Uri(servicePointUri, UserModeConstants.TenantId);
            ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(serviceRoot,
                async () => await AcquireTokenAsyncForUser());
            return activeDirectoryClient;
        }

public static async Task<string> AcquireTokenAsyncForUser()
        {
            return await GetTokenForUser();
        }

public static async Task<string> GetTokenForUser()
        {
            if (TokenForUser == null)
            {
                var redirectUri = new Uri("https://localhost");
                AuthenticationContext authenticationContext = new AuthenticationContext(UserModeConstants.AuthString, false);
                AuthenticationResult userAuthnResult = await authenticationContext.AcquireTokenAsync(GlobalConstants.ResourceUrl,
                    UserModeConstants.ClientId, redirectUri, new PlatformParameters(PromptBehavior.RefreshSession));
                TokenForUser = userAuthnResult.AccessToken;
            }
            return TokenForUser;
        }
+4
source share
2 answers

Active Directory Authentication Library , using the sample code, help developers use the authentication features for your .NET client on various platforms, including the Windows desktop, Windows Store, Xamarin iOS, and Xamarin Android .

-, active-directory-dotnet-webapp-openidconnect. API Azure AD -, active-directory-dotnet-graphapi-web.

Microsoft Azure, :

Azure

+5

, localhost, ? , azure

powershell login.correct me, .

+2

Source: https://habr.com/ru/post/1671672/


All Articles