Skip to content

Commit

Permalink
fix for "Custom token credentials unsupported for Graph APIs" (#288)
Browse files Browse the repository at this point in the history
* fix for "Custom token credentials unsupported for Graph APIs"

* Added null check for custom credential creation.

* fixed typo.
  • Loading branch information
Hovsep authored Apr 23, 2018
1 parent 4265d81 commit e058416
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,20 @@ public AzureCredentials(MSILoginInformation msiLoginInformation, AzureEnvironmen
this.msiTokenProviderFactory = new MSITokenProviderFactory(msiLoginInformation);
}

public AzureCredentials(ServiceClientCredentials credentials, string tenantId, AzureEnvironment environment)
public AzureCredentials(
ServiceClientCredentials armCredentials,
ServiceClientCredentials graphCredentials,
string tenantId, AzureEnvironment environment)
: this(tenantId, environment)
{
credentialsCache[new Uri(Environment.ManagementEndpoint)] = credentials;
if (armCredentials != null)
{
credentialsCache[new Uri(Environment.ManagementEndpoint)] = armCredentials;
}
if (graphCredentials != null)
{
credentialsCache[new Uri(Environment.GraphEndpoint)] = graphCredentials;
}
}

private AzureCredentials(string tenantId, AzureEnvironment environment)
Expand Down Expand Up @@ -147,6 +157,11 @@ public async override Task ProcessHttpRequestAsync(HttpRequestMessage request, C
{
credentialsCache[adSettings.TokenAudience] = new TokenCredentials(this.msiTokenProviderFactory.Create(adSettings.TokenAudience.OriginalString));
}
// no token available for communication
else
{
throw new AuthenticationException($"Cannot communicate with server. No authentication token available for '{adSettings.TokenAudience}'.");
}
}
await credentialsCache[adSettings.TokenAudience].ProcessHttpRequestAsync(request, cancellationToken);
}
Expand Down

0 comments on commit e058416

Please sign in to comment.