Question

I have tested Twitter and LinkedIn and I seem to be able to get these working eventually, but I just cannot find enough material to get the Google connectors to work. When using the Google Calendar connector I am trying to collect the token with - #[flowVars['tokenId']] but the value always comes out as null. Am I doing something wrong? Can someone please help?

Thanks,

Ash.

Was it helpful?

Solution

Answered my own question for anyone else struggling with the same issue -

Managing OAuth Tokens (optional)

Configure ObjectStore

To keep data persistent you need to store it somewhere, it is recommended you use ObjectStore for this. Install an ObjectStore connector. Configure it like this in your application:

<objectstore:config name="ObjectStore" doc:name="ObjectStore" />

Storing Tokens After Authorization

After the authorization dance is done, the accessTokenId for the service you are invoking is available as a flow variable called OAuthAccessTokenId. You must persist this ID so you can use it in future invocations of your connector. This example shows how to store this variable into ObjectStore under the key accessTokenId.

<flow name="authorize-google" doc:name="authorize-google">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="authorize" doc:name="HTTP"/>
        <google-contacts:authorize config-ref="Google_Contacts" doc:name="Authorize GContacts"/>
        <objectstore:store config-ref="ObjectStore" key="accessTokenId" value-ref="#[flowVars['OAuthAccessTokenId']]" overwrite="true" doc:name="ObjectStore"/>    
</flow>

Using Your Access Token

Any invocation of your connector must load the access token from ObjectStore and reference it. This example shows loading it from ObjectStore and checking if it was set, before proceeding.

<enricher target="#[flowVars['accessTokenId']]" doc:name="Message Enricher">
            <objectstore:retrieve config-ref="ObjectStore" key="accessTokenId" defaultValue-ref="#['']" doc:name="Get AccessToken"/>
</enricher>
<expression-filter expression="#[flowVars['accessTokenId'] != '']" doc:name="Is Access Token Set"/>

Once accessTokenId is available as a flow variable, you can reference it in your connector operations:

<google-contacts:get-contacts config-ref="Google_Contacts" accessTokenId="#[flowVars['accessTokenId']]" />

More details here - http://www.mulesoft.org/documentation/display/34X/Using+a+Connector+to+Access+an+OAuth+API

Heres how it look in the studio - http://imgur.com/DtLodel

Thanks,

Ash.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top