locked
Authentication information is not given in the correct format. Check the value of Authorization header in Azure Ratecard Apis RRS feed

  • Question

  • i use java compiler

    To fetch rate card,i'm using below api

    i check postman is working , java for me Authentication information is not given in the correct format. Check the value of Authorization header message

    Tuesday, May 22, 2018 8:48 AM

Answers

  • @Heywei7 - The main problem that I see based on the code that you've posted on the forum is, you are calling the API once with the token with the client automatically redirecting you to the link using the same auth headers and that’s why you're getting the error. You need to do 2 things. First create HttpsURLConnection with followRedirects set to false. Then call the RateCard API and get the redirect url and make another call to the redirect url without any auth headers.

    -----------------------------------------------------------------------------------------------------------------------------------
    If this answer was helpful, click “Mark as Answer” or Up-Vote. To provide additional feedback on your forum experience, click here 

    Sunday, May 27, 2018 5:11 AM

All replies

  • Suggest you to check this MSDN thread - https://social.msdn.microsoft.com/Forums/en-US/72de1bac-9657-434f-8811-365c9fe09a69/authentication-information-is-not-given-in-the-correct-format-check-the-value-of-authorization?forum=windowsazurepurchasing which is similar in nature. Let us know if this helps.

    -----------------------------------------------------------------------------------------------------------------------------------
    If this answer was helpful, click “Mark as Answer” or Up-Vote. To provide additional feedback on your forum experience, click here 

    Tuesday, May 22, 2018 9:13 AM
  • Hi

    i know thread, but did not solve my problem,

    this thread have code sample and my code doesn't make too much of a difference.


    Tuesday, May 22, 2018 9:36 AM
  • Could you share the error message and the code snippet? Conceal sensitive information in your code before posting here.

    Tuesday, May 22, 2018 10:03 AM
  • public String getTokenTest() throws Exception {
    		ExecutorService service = Executors.newFixedThreadPool(1);
    		String logginUrl = "https://login.microsoftonline.com/" + TENANT + "/oauth2/authorize";
    		AuthenticationContext authContext = new AuthenticationContext(logginUrl, false, service);
    		ClientCredential clientCred = new ClientCredential(CLIENT_ID, KEY);
    		Future<AuthenticationResult> future = authContext.acquireToken("https://management.azure.com/", clientCred,
    				null);
    		AuthenticationResult authResult = future.get();
    		System.out.println("Token " + authResult.getAccessToken());
    		return authResult.getAccessToken();
    	}
    
    public void rateCard() throws Exception {
    		HttpClient demo = HttpClientBuilder.create().build();
    		HttpGet httpGet = new HttpGet("https://management.azure.com/subscriptions/XXXXXXXXXXXXX"
    				+ "/providers/Microsoft.Commerce/RateCard?api-version=2016-08-31-preview&$filter=OfferDurableId"
    				+ "%20eq%20'MS-AZR-0025P'%20and%20Currency%20eq%20'USD'%20and%20Locale%20eq%20'en-US'%20and%20RegionInfo%20eq%20'US'");
    		httpGet.addHeader("Authorization ", "Bearer " + getTokenTest());
    		httpGet.addHeader("Content-Type", "application/json");
    		HttpResponse response = demo.execute(httpGet);
    		String responseString = EntityUtils.toString(response.getEntity());
    		System.out.println(responseString);
    	}
    
    

    <?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidAuthenticationInfo</Code><Message>Authentication information is not given in the correct format. Check the value of Authorization header.
    RequestId:2e653465-901e-0104-3aba-f182b4000000
    Time:2018-05-22T10:46:03.4168701Z</Message></Error>

    This is my code and error message

    Tuesday, May 22, 2018 10:47 AM
  • Hello Sadiqh Ahmed

    can you help me this problem?

    i need this api for my job

    Thanks



    • Edited by Heywei7 Thursday, May 24, 2018 8:33 AM delete text
    Thursday, May 24, 2018 8:33 AM
  • @Heywei7 - The main problem that I see based on the code that you've posted on the forum is, you are calling the API once with the token with the client automatically redirecting you to the link using the same auth headers and that’s why you're getting the error. You need to do 2 things. First create HttpsURLConnection with followRedirects set to false. Then call the RateCard API and get the redirect url and make another call to the redirect url without any auth headers.

    -----------------------------------------------------------------------------------------------------------------------------------
    If this answer was helpful, click “Mark as Answer” or Up-Vote. To provide additional feedback on your forum experience, click here 

    Sunday, May 27, 2018 5:11 AM
  • @Sadiqh Ahmed

    Thanks,is work

    Monday, May 28, 2018 9:38 AM
  • You're welcome. :)
    Monday, May 28, 2018 9:48 AM