title: OAuth 2.0 implementation in Mule
body: <p>I am working on a project in which I need to expose some of its method over web service and that I am doing using Mule by following RAML and to implement security, OAuth 2.0 has been proposed. I am able to validate the client for its 'client_id' and 'client_secret' but for that I have given the credentials in configuration file only. Now I need to fetch the client details from database. I tried using 'preFlow-ref' and another flow is being called where I am able to retrieve 'client_id' and 'client_secret' but don't know how to give callback to OAuth. </p>
  
  <pre><code> &lt;spring:beans&gt;
       &lt;spring:bean id="oauthTokenStore" name="oauthTokenStore" class="database_connection.MyClientStore"/&gt;
   &lt;/spring:beans&gt;
  
   &lt;oauth2-provider:config 
       name="oauth2Provider"
       providerName="TweetBook"
       supportedGrantTypes="CLIENT_CREDENTIALS"
       preFlow-ref="apiFlow1"
       host="localhost"
       port="8083"
       authorizationEndpointPath="tweetbook/api/authorize"
       accessTokenEndpointPath="tweetbook/api/token"
       scopes="READ_PROFILE WRITE_PROFILE READ_BOOKSHELF WRITE_BOOKSHELF"&gt;
   &lt;/oauth2-provider:config&gt;
  
   &lt;apikit:config name="Router" raml="src/main/api/api.raml" consoleEnabled="true" consolePath="console" doc:name="Router"/&gt;
  
   &lt;flow name="apiFlow1"&gt;          
       &lt;set-variable variableName="client_id" value="1234567890abcd" doc:name="Client id"/&gt;
       &lt;logger message="entered DB flow" level="INFO" doc:name="Logger"/&gt;
       &lt;db:select config-ref="Generic_Database_Configuration" doc:name="Database"&gt;
           &lt;db:dynamic-query&gt;&lt;![CDATA[select client_secret from table1 where client_id = #[flowVars.client_Id]]]&gt;&lt;/db:dynamic-query&gt;
      &lt;/db:select&gt;
      &lt;logger message="exit db flow" level="INFO" doc:name="Logger"/&gt;
   &lt;/flow&gt;
  </code></pre>