Authorization with .Net

development
Tags: #<Tag:0x00007fd5e1f92540>

#1

Hi All,

I’m trying to get access to the user-genres via the API with .Net, the authorization keeps failing. Can anyone help? The snippet of the code is:-

HttpWebRequest req = DirectCast(WebRequest.Create(“https:musicbrainz/ws/2/recording/ef2ca8c7-ba44-427b-92d9-82161428d24e?inc=genres+user-genres”, HttpWebRequest);
req.Method = “GET”;
req.UserAgent = AppNameVersion;
req.Credentials = New NetworkCredential(Base64Encode(username), Base64Encode(pw))

//Make the call.
response = DirectCast(req.GetResponse(), HttpWebResponse);

It is only when I add the “+user-genres” it fails (error 401).

I have tried with and without Base64 encoding, and the nominal “http://musicbrainz.org”, with Basic and Digest modes…

Any pointers appreciated.

Thanks in advance
PoQStacker


#2

You do not need to authenticate to get the genre tag.
You need to provide a user agent, this is for rate limiting and so they can contact you if there are problems with your app.

Looking at the .net api documentation you need to provide it with the real username and password, you do not need to base64 encode this.
The api supports digest authentication and I think the .net api selects the authentication method automatically.


#3

That’s not entirely correct, you need credentials if requesting user-genres, user-tags etc., because this returns data for the authenticated user.

But I agree with the base64 encoding part, the documentation of NetworkCredential does not indicate this is needed, and as I understand it the underlying implementation should make sure to use username and password as expected by the authenticationm mechanism used in the request .


#4

I have tried it with and without the Base64 encoding - always error 401.

I have looked here, stackoverflow, github, codeproject… for a coding example of authorised access, but without luck.

If anyone has a .net coding example that would be very helpful.


#5

I have discovered bugs in the NetworkCredential() function which prevented it from working.

All good now. :slight_smile:


#6

Great. Can you share with us what finally worked?


#7

I found this on SO:-

https://stackoverflow.com/questions/3109507/httpwebrequests-sends-parameterless-uri-in-authorization-header/3117042#3117042


#8

Hi all, I am having trouble with submitting “user-genre” (tag) via the API. It rejects the submission with status 401 (Unauthorized) - the url is:-

https://musicbrainz.org/ws/2/tag?client=PoQStacker-1.0.0.0

I am using the same http authorisation digest that works for GET’ing “user-genre”

I am setting the headers:-

useragent: PoQStacker/1.0.0.0( poqstacker@gmail.com )
contenttype: application/xml; charset=utf-8
contentlength: (content.length)

I am setting the content to:-

<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#"><recording-list><recording id="ef2ca8c7-ba44-427b-92d9-82161428d24e"><user-tag-list><user-tag vote="downvote"><name>swing</name></user-tag></user-tag-list></recording></recording-list></metadata>

Can anyone assist?

Thanks in advance