0

I am running the normal AzureAD commands from a new Azure VM which is behind firewall . I believe the required firewall ports are open to login.microsoftonline.com but cannot say for sure with the error message if its really a firewall issue. Has anyone faced the same exception and it turned out to be a firewall issue ?

Running below regular commands to connect.

import-module azureadpreview

Connect-AzureAD -TenantId $script:Tenantid -ApplicationId $script:ClientAppId -CertificateThumbprint $script:CertificateThumbprint

$allapps=Get-AzureADApplication -All 1

Exception Message:

Error Message: Error reading JToken from JsonReader. Path '', line 0, position 0.
Error StackTrace:    at Newtonsoft.Json.Linq.JToken.ReadFrom(JsonReader reader, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings)
   at Microsoft.Open.AzureAD16.Client.Configuration.<>c.<.cctor>b__47_0(String methodName, IRestResponse response) in C:\__w\1\s\src\dev\PowerShell.V2\AzureAD16.Client\Client\Con
figuration.cs:line 147
   at Microsoft.Open.AzureAD16.Api.ApplicationApi.GetApplicationsWithHttpInfo(String tenantId, String authorization, String cmdletName, String clientRequestId, String apiVersion,
 String objectId, Nullable`1 all, Nullable`1 top, String skiptoken, String filter, String orderby) in C:\__w\1\s\src\dev\PowerShell.V2\AzureAD16.Client\Api\ApplicationApi.cs:line
 2782
   at Microsoft.Open.AzureAD16.PowerShell.GetApplications.ProcessRecord() in C:\__w\1\s\src\dev\PowerShell.V2\AzureAD16.PowerShell\AzureAD16.PowerShell.AutoGen\API\ApplicationApi
.cs:line 1010
   at System.Management.Automation.Cmdlet.GetResults()
   at System.Management.Automation.Cmdlet.<Invoke>d__40.MoveNext()
   at System.Management.Automation.MshCommandRuntime._WriteObjectsSkipAllowCheck(Object sendToPipeline)
   at System.Security.SecurityContext.Run(SecurityContext securityContext, ContextCallback callback, Object state)
   at System.Management.Automation.MshCommandRuntime.WriteObject(Object sendToPipeline, Boolean enumerateCollection)
   at System.Management.Automation.Cmdlet.WriteObject(Object sendToPipeline, Boolean enumerateCollection)
   at Microsoft.Open.AzureAD16.PowerShell.GetApplication.ProcessRecord() in C:\__w\1\s\src\dev\PowerShell.V2\AzureAD16.PowerShell\AzureAD16.PowerShell.AutoGen\API\ApplicationApi.
cs:line 290
   at System.Management.Automation.CommandProcessor.ProcessRecord()

I tried copying the AzureADpreview module again but no go.

toyota Supra
  • 3,181
  • 4
  • 15
  • 19

1 Answers1

0

Error Message: Error reading JToken from JsonReader. Path '', line 0, position 0. Error StackTrace: tNewtonsoft.Json.Linq.JToken.ReadFrom(JsonReader reader, JsonLoadSettings settings) at Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings) at Microsoft.Open.AzureAD16.Client.Configuration.<>c.<.cctor>b__47_0(String methodName, IRestResponse response) in C:__w\1\s\src\dev\PowerShell.V2\AzureAD16.Client\Client\Con figuration.cs:line 147 at ....

This error usually occurs, firewall rule, or company network blocking the traffic.

To resolve the issue, make sure to add port in your firewall for Azure AD:

In virtual machine -> Networking ->Add inbound port rule:

enter image description here

Outbound port rule:

enter image description here

In Azure vm you can check the network connectivity to the Azure AD endpoints using PowerShell commands Test-NetConnection or Test-Connection.

enter image description here

Update the AzureAD PowerShell module to the latest version. To install module use this below command and enter latest version:

Find-Module -Name AzureADPreview -AllVersions
Install-Module -Name AzureADPreview -RequiredVersion 2.0.2.183

![enter image description here](https://i.imgur.com/3X73PdT.png)

Now, In Azure virtual machine sign-in portal generated a certificate when I use the below command got result successfully:

$certname = "test123"    
$cert = New-SelfSignedCertificate -Subject "CN=$certname" -CertStoreLocation "Cert:\CurrentUser\My" -KeyExportPolicy Exportable -KeySpec Signature -KeyLength 2048 -KeyAlgorithm RSA -HashAlgorithm SHA256
Export-Certificate -Cert $cert -FilePath "C:\Users\imran123\Desktop\New folder\test.cer"

Uploaded the .cer certificate in Azure AD Application

enter image description here

import-module azureadpreview
Connect-AzureAD -TenantId Tenantid -ApplicationId ClientAppId -CertificateThumbprint CertificateThumbprint
$allapps=Get-AzureADApplication -All 1

Output:

enter image description here

Imran
  • 3,875
  • 2
  • 3
  • 12