Skip to content

Commit

Permalink
More definitive resource id matching (Azure#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu authored Aug 21, 2017
1 parent bced924 commit c7032da
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
package com.microsoft.azure.credentials;

import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.AzureEnvironment.Endpoint;
import com.microsoft.rest.credentials.TokenCredentials;
import okhttp3.OkHttpClient;
import okhttp3.Request;

import java.io.IOException;
import java.net.Proxy;
import java.util.Map;

/**
* AzureTokenCredentials represents a credentials object with access to Azure
Expand All @@ -39,15 +41,18 @@ public AzureTokenCredentials(AzureEnvironment environment, String domain) {

@Override
protected final String getToken(Request request) throws IOException {
String host = request.url().host();
for (String endpoint : environment().endpoints().values()) {
if (host.contains(endpoint)) {
// Remove leading dots
host = endpoint.replaceAll("^\\.*", "");
break;
String host = request.url().toString().toLowerCase();
String resource = environment().activeDirectoryResourceId();
for (Map.Entry<String, String> endpoint : environment().endpoints().entrySet()) {
if (host.contains(endpoint.getValue())) {
if (endpoint.getKey().equals(Endpoint.KEYVAULT.identifier())) {
resource = String.format("https://%s/", endpoint.getValue().replaceAll("^\\.*", ""));
break;
} else if (endpoint.getKey().equals(Endpoint.GRAPH.identifier())) {
resource = environment().graphEndpoint();
}
}
}
String resource = String.format("https://%s/", host);
return getToken(resource);
}

Expand Down

0 comments on commit c7032da

Please sign in to comment.