我已使用Mule密码授予类型流实施了OAuth2提供程序,如https://developer.mulesoft.com/docs/display/current/Creating+an+OAuth+2.0a+Web+Service+Provider所示。但它以JSON格式返回令牌响应;我想用XML格式,我该怎么做?
<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>
答案 0 :(得分:0)
我认为如果你想这样做,你需要在流程的最后创建一个选择,然后如果你接受&#39;标题相同&#39; application / xml&#39;你把自定义变换器从json放到xml。因为OAuth2 Spec表示返回的标记应该是json。我用spring security oauth2做了这个,但这是一个定制。
答案 1 :(得分:0)
您可能想要创建一个新的http mule流,它调用oauth2-provider令牌端点并将其响应转换为xml。
创建一个新的mule配置文件:
<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>
希望这会有所帮助。