Question

I have created a mule OAuth2 provider using the config below and everything works great.

What I would like to do is store the client details in a data store to allow me to quickly add clients without deploying my application again. Is that possible or do I have to hardcode the clients into the mule flow?

<oauth2-provider:config name="OAuth_provider_module" accessTokenEndpointPath="oauth/token" authorizationEndpointPath="oauth/authorize" doc:name="OAuth provider module" scopes="READ_PROFILE" resomuurceOwnerSecurityProvider-ref="resourceOwnerSecurityProvider" providerName="Provider" loginPage="login.html">
    <oauth2-provider:clients>
        <oauth2-provider:client clientId="ccccccc" secret="ddddddd" type="CONFIDENTIAL" clientName="blah" description="blah">
            <oauth2-provider:redirect-uris>
                <oauth2-provider:redirect-uri>http://localhost:3000/callback</oauth2-provider:redirect-uri>
            </oauth2-provider:redirect-uris>
            <oauth2-provider:authorized-grant-types>
                <oauth2-provider:authorized-grant-type>AUTHORIZATION_CODE</oauth2-provider:authorized-grant-type>
            </oauth2-provider:authorized-grant-types>
            <oauth2-provider:scopes>
                <oauth2-provider:scope>READ_PROFILE</oauth2-provider:scope>
            </oauth2-provider:scopes>
        </oauth2-provider:client>
    </oauth2-provider:clients>
</oauth2-provider:config>
Était-ce utile?

La solution

Should be plenty of options if you look at the Mule OAuth 2 guide. If you want to manage your clients externally, injecting your configuration or client store into a custom Spring bean might be a good option.

<spring:bean class="YourClass" init-method="initialize">
   <spring:property name="config" value="#{OAuth_provider_module.configuration}" />
</spring:bean>

and in your custom class:

private Configuration configuration;
public void initialize() {
   configuration.getClientStore()
     etc...
}

public void setConfig(Configuration configuration) {
  this.configuration = configuration;
}

or alternatively, inject the client store directly (like in the guide example) with

name="clientRegistration" value="#{OAuth_provider_module.configuration.clientStore}"

and

setClientRegistration(final ClientRegistration clientRegistration)

Autres conseils

In the end I changed my configuration to

<oauth2-provider:config name="OAuth_provider_module" 
                        accessTokenEndpointPath="oauth/token" 
                        authorizationEndpointPath="oauth/authorize" 
                        doc:name="OAuth provider module" 
                        scopes="READ_PROFILE" 
                        resourceOwnerSecurityProvider-ref="resourceOwnerSecurityProvider" 
                        clientStore-ref="customClientStore"
                        providerName="TLRG Authentication" 
                        loginPage="login.html">
</oauth2-provider:config>

And injected the clientStore-ref using spring.

All I had to do was make the customClientStore implement org.mule.modules.oauth2.provider.client.ClientStore and away I went.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top