简体   繁体   中英

Azure Data Lake Store “The access token is not provided in the 'Authorization' header” using HttpClient

I'm having issues trying to access Azure Data Lake Store via the WebHDFS APIs using an HttpClient in .NET

This is my code:

using (var client = new HttpClient())
{
    HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Put, resourceUri);

    message.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken);
    message.Content = new StringContent(JsonConvert.SerializeObject(body));
    message.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

    var result = await client.SendAsync(message);
    var content = await result.Content.ReadAsStringAsync();

    result.EnsureSuccessStatusCode();
}

Which returns me a 401 with this message: "The access token is not provided in the 'Authorization' header"

The weird thing is if I take the exact accessToken and resourceUri and put it in Postman it works fine (201).

I've added the application under Access control, and in the Data Explorer > Access tab, and have given full rights (Read, Write, Execute).

I even rewrote this using RestSharp yet the same error is given to me, I checked the JWT token it is definitely correct and returning data when I use it in Postman. It seems like the header is being stripped out somewhere.

This is driving me crazy, I can't figure out what I am doing wrong! Can anyone please help?

The issue seems to be related to a redirect that was happening that added an extra parameter added to the operation in the resource URI.

The parameter was "write=true". So I've updated the Resource URI to include the parameter.

ie for PUT operation " https://yourstore.azuredatalakestore.net/webhdfs/v1/xxx?op=CREATE&write=true "

Very weird behaviour but it works now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM