0

How to convert the Laravel Passport rest API package authorization access token response in XML format.

Laravel version: 5.4,
Laravel/Passport version: 4.0.3

e.g. Suppose when calling the API url www.mydomain.com/oauth/token using the postman getting response in JSON format like

{
"token_type": "Bearer",
"expires_in": 31536000,
"access_token": "xxxxxxxxxxxxxxxxxxxxxxxx",
"refresh_token": "xxxxxxxxxxxxxxxxxxxxxxxx"
}

I want to change this output response in XML format like

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <access_token>xxxxxxxxxxxxxxxxxxxxxxxx</access_token>
   <expires_in>31536000</expires_in>
   <refresh_token>xxxxxxxxxxxxxxxxxxxxxxxx</refresh_token>
   <token_type>Bearer</token_type>
</root>
Shamsi786
  • 129
  • 1
  • 10
  • You cann create a middleware to add on the login route that changes the return reponse to and xml (changing the headers and the content). have you tried to change the header "Expects" on the request ? – N69S Mar 11 '20 at 12:53
  • please check this https://stackoverflow.com/questions/26964136/how-do-i-convert-json-to-xml/26964222 – Kamlesh Paul Mar 11 '20 at 13:04
  • Thanks for your reply @N69S. I have not tried using any middleware, but tried to change the header Content-type but not helped that – Shamsi786 Mar 11 '20 at 13:25
  • Thanks for your reply @KamleshPaul. I have checked that, but in I am asking about changing the Laravel Passport package default route response conversion for which I do not have any access to them. Which is inbuilt by the package. – Shamsi786 Mar 11 '20 at 13:27
  • create custom route and in that route call passport route and convert json response to xml – Kamlesh Paul Mar 11 '20 at 13:29

0 Answers0