mattbrailsford / umbraco-authu

An Umbraco plugin to add an OAuth API endpoint to allow authenticated Members/Users via OAuth
MIT License
71 stars 22 forks source link

media type 'application/x-www-form-urlencoded' is not supported #17

Closed ddineen closed 6 years ago

ddineen commented 7 years ago

Getting this when i post to oauth/token "Message": "The request entity's media type 'application/x-www-form-urlencoded' is not supported for this resource."

Umbraco 7.7.1

biapar commented 7 years ago

Hi,

How Do you call the service?

ddineen commented 7 years ago

In Asp.NET - this worked for me. The issue was related to the custom headers <add name="Access-Control-Allow-Headers" value="content-type .... Then the following code worked out fine.

string Url = rootUrl + "/umbraco/oauth/token";
                    string paramaters = "grant_type=password&username=" + siteSettings.GetApiUsername() + "&password=" + siteSettings.GetApiPassword();
                    string contentType = "application/x-www-form-urlencoded";
                    string sResponse = "";
                    wc.Headers.Add("Content-Type", contentType);
                    Uri u = new Uri(Url);
                    sResponse = await wc.UploadStringTaskAsync(u, "POST", paramaters);

Hope this helps!