Using the default Visual Studio 2013 Web API project template with individual user accounts, and posting to the /token endpoint with an Accept header of application/xml, the server still returns the response in JSON:
{"access_token":"...","token_type":"bearer","expires_in":1209599}
Is there a way to get the token back as XML?
I normally just remove the XmlFormatter altogether.
Add the line above in your WebApiConfig class...
Could you retry by doing the following steps:
In the
WebApiConfig.Register()
, specifytake a look here i hope it can help how to set a Web API REST service to always return XML not JSON
Ok I had such a fun time trying to figure this out using OWIN I thought I would share my solution with the community, I borrowed some insight from other posts https://stackoverflow.com/a/26216511/1148288 and https://stackoverflow.com/a/29105880/1148288 along with the concepts Alexei describs in his post. Nothing fancy doing with implementation but I had a requirement for my STS to return an XML formatted response, I wanted to keep with the paradigm of honoring the Accept header, so my end point would examine that to determine if it needed to run the XML swap or not. This is what I am current using:
Of course you would then wire this up during startup config like so:
Hope that helps any other lost souls that find there way to the this post seeking to do something like this!
According to RFC6749 the response format should be JSON and Microsoft implemented it accordingly. I found out that JSON formatting is implemented in
Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerHandler
internal class with no means of extension.I also encountered the need to have token response in XML. The best solution I came up with was to implement HttpModule converting JSON to XML when stated in Accept header.