1
votes

I have implemented OAuth2 provider using Mule Password grant type flow as shown on https://developer.mulesoft.com/docs/display/current/Creating+an+OAuth+2.0a+Web+Service+Provider. But it is returning token response in JSON format; I want it in XML format how can I do that ?

    <spring:beans>     
        <ss:authentication-manager id="resourceOwnerAuthenticationManager">
            <ss:authentication-provider>
                <ss:user-service id="resourceOwnerUserService">
                    <ss:user name="user" password="password" authorities="RESOURCE_OWNER" />
                </ss:user-service>
            </ss:authentication-provider> 
        </ss:authentication-manager>
    </spring:beans>

    <mule-ss:security-manager>
        <mule-ss:delegate-security-provider
            name="resourceOwnerSecurityProvider"
            delegate-ref="resourceOwnerAuthenticationManager" />
    </mule-ss:security-manager>

<oauth2-provider:config
        name="oauth2Provider"
        providerName="SampleAPI"
        supportedGrantTypes="RESOURCE_OWNER_PASSWORD_CREDENTIALS"
        port="8083"
        authorizationEndpointPath="sampleapi/api/authorize"
        accessTokenEndpointPath="sampleapi/api/token"
        resourceOwnerSecurityProvider-ref="resourceOwnerSecurityProvider"
        scopes="READ_RESOURCE POST_RESOURCE" doc:name="OAuth provider module">
            <oauth2-provider:clients>
                <oauth2-provider:client clientId="myclientid3" secret="myclientsecret"
                                        type="CONFIDENTIAL" clientName="Mule Bookstore" description="Mule-powered On-line Bookstore">
                    <oauth2-provider:redirect-uris>
                        <oauth2-provider:redirect-uri>http://localhost*</oauth2-provider:redirect-uri>
                    </oauth2-provider:redirect-uris>
                    <oauth2-provider:authorized-grant-types>
                        <oauth2-provider:authorized-grant-type>PASSWORD</oauth2-provider:authorized-grant-type>
                    </oauth2-provider:authorized-grant-types>
                    <oauth2-provider:scopes>
                        <oauth2-provider:scope>READ_RESOURCE</oauth2-provider:scope>
                        <oauth2-provider:scope>POST_RESOURCE</oauth2-provider:scope>
                    </oauth2-provider:scopes>
                </oauth2-provider:client>
            </oauth2-provider:clients>
    </oauth2-provider:config>
2
Why would you need in and xml format. ?Naveen Raj
Because My RAML Services are in XML format and I want token to be in that format so that I dont need o have one formats for OAuth2 token and another format for REST Services. Can it possible. OAuth2 Provider with SPring Security has that capability. Can it possible in Mule OAuth2 implementation ?Nitin Pawar
I Hope you need only the OAuth token . In that case you can encapsulate the component that calls retrieves the Token i a message enricher and then set only the token to the FlowVariables and use them whenever you need in the flow . Will that work for your use case ?Naveen Raj
Thank you Neeraj. Actually in my requirement only OAuth2 and REST service is hosted on Mule ESB. REST consumer is are multiple that is Java based and Microsoft SSIS based; I need token in XML format as well.Nitin Pawar
Hello Naveen, Isn't it possible ? As my Services are communicating using XML I would like to have TOKEN response in XML format as well.Nitin Pawar

2 Answers

0
votes

I think if you want to do this you need create a choice at the end of the flow, and then if the 'Accept' header is equal 'application/xml' you put a custom transformer from json to xml. Because the OAuth2 Spec says the token returned should be a json. I did it with spring security oauth2 but this is a customization.

0
votes

You might want to create a new http mule flow which invokes the oauth2-provider token endpoint and convert its response to xml.

create a new mule configuration file:

<flow name="token-json-to-xmlFlow">
   <http:listener> <-- new token endpoint
   <http:request> <-- invoke the oauth2 provider token 
   <transform-message> <-- json to xml transformer
</flow>

hope this helps.