org.mule.modules

mule-module-google-tasks

config-with-oauth

Namespacehttp://www.mulesoft.org/schema/mule/google-tasks
Schema Locationhttp://www.mulesoft.org/schema/mule/google-tasks/current/mule-google-tasks.xsd  (View Schema)
Schema Version1.0
Minimum Mule Version3.4

Module Overview

Google Tasks Cloud connector. This connector covers almost all the Google Tasks API v3 using OAuth2 for authentication.

Summary

Configuration
<google-tasks:config-with-oauth>
Configure an instance of this module
Message Processors
<google-tasks:clear-tasks>
Clears all completed tasks from the specified task list.
<google-tasks:delete-task>
Deletes the specified task from the task list.
<google-tasks:delete-task-list>
Deletes the authenticated user's specified task list.
<google-tasks:get-task-by-id>
Returns the specified task.
<google-tasks:get-task-list-by-id>
Returns the authenticated user's specified task list
<google-tasks:get-task-lists>
Returns all the authenticated user's task lists.
<google-tasks:get-tasks>
Returns all tasks in the specified task list.
<google-tasks:insert-task>
Creates a new task on the specified task list
<google-tasks:insert-task-list>
Creates a new task list and adds it to the authenticated user's task lists.
<google-tasks:move>
Moves the specified task to another position in the task list.
<google-tasks:update-task>
Updates the specified task.
<google-tasks:update-task-list>
Updates the authenticated user's specified task list.

Configuration

To use the this module within a flow the namespace to the module must be included. The resulting flow will look similar to the following:

<mule xmlns="http://www.mulesoft.org/schema/mule/core"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:google-tasks="http://www.mulesoft.org/schema/mule/google-tasks"
      xsi:schemaLocation="
               http://www.mulesoft.org/schema/mule/core
               http://www.mulesoft.org/schema/mule/core/current/mule.xsd
               http://www.mulesoft.org/schema/mule/google-tasks
               http://www.mulesoft.org/schema/mule/google-tasks/current/mule-google-tasks.xsd">

      <!-- here goes your flows and configuration elements -->

</mule>

This module is configured using the config element. This element must be placed outside of your flows and at the root of your Mule application. You can create as many configurations as you deem necessary as long as each carries its own name.

Each message processor, message source or transformer carries a config-ref attribute that allows the invoker to specify which configuration to use.

Attributes
TypeNameDefault ValueDescriptionJava TypeMIME TypeEncoding
xs:string name Optional. Give a name to this configuration so it can be later referenced.
xs:string applicationName Mule-GoogleTasksConnector/1.0 Optional. Application name registered on Google API console
xs:string consumerKey The OAuth2 consumer key
xs:string consumerSecret The OAuth2 consumer secret
identifierPolicy EMAIL Optional. This policy represents which id we want to use to represent each google account.
xs:string scope https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/tasks Optional. The OAuth scopes you want to request
xs:string authorizationUrl https://accounts.google.com/o/oauth2/auth Optional. The URL defined by the Service Provider where the resource owner will be redirected to grant authorization to the connector
xs:string accessTokenUrl https://accounts.google.com/o/oauth2/token Optional. The URL defined by the Service Provider to obtain an access token

OAuth

This connector uses OAuth as an authorization and authentication mechanism with automatic saving and restoring of access tokens. Every message processor in this connector has an extra attribute entitled accessTokenId which is an identification of the user authorizing the conenctor. In order to obtain an access token identification you need to first call the authroize message processor.

Authorizing the connector is a simple process of calling:

    <google-tasks:authorize/>

The call to authorize message processor must be made from a message coming from an HTTP inbound endpoint as the authorize process will reply with a redirect to the service provider. The following is an example of how to use it in a flow with an HTTP inbound endpoint:

    <flow name="authorizationAndAuthenticationFlow">
        <http:inbound-endpoint host="localhost" port="8080" path="oauth-authorize"/>
        <google-tasks:authorize/>
    </flow>

If you hit that endpoint via a web-browser it will initiate the OAuth dance, redirecting the user to the service provider page and creating a callback endpoint so the service provider can redirect back once the user has been authenticated and properly authorized the connector. Once the callback gets called then the connector will automatically issue an access token identifier that you need to save as either a cookie or a database record for any subsequent calls.

The authorize message processor also supports the following attributes:

Authorize Attributes
NameDefault ValueDescription
access_type online Optional. Indicates if your application needs to access a Google API when the user is not present at the browser. Use offline to get a refresh token and use that when the user is not at the browser. Default is online
force_prompt auto Optional. Indicates if google should remember that an app has been authorized or if each should ask authorization every time. Use force to request authorization every time or auto to only do it the first time. Default is auto
authorizationUrl https://accounts.google.com/o/oauth2/auth Optional. The URL defined by the Service Provider where the resource owner will be redirected to grant authorization to the connector
accessTokenUrl https://accounts.google.com/o/oauth2/token Optional. The URL defined by the Service Provider to obtain an access token

After Authorization

The authorize message processor is an intercepting one. If the connector is not authorized yet, it will redirect to the service provider so the user can authorize the connector. This is the reason as to why the authorize needs to be behind and http:inbound-endpoint. The service provider upon successful authentication and authorization then will call back the connector. The connector will extract information from that call, set its internal state to authorized, and then continue execution. Continuing execution means executing everything that was after the authorize whose execution got interrupted because the connector was not authorized.

  <flow name="authorizationAndAuthenticationFlow">
      <http:inbound-endpoint host="localhost" port="8080" path="oauth-authorize"/>
      <google-tasks:authorize/>
      <http:response-builder status="200">
          <set-payload value="You have successfully authorized the connector"/>
      </http:response-builder>
  </flow>

In the previous example we added the http:response-build (notice that this element is available only in Mule 3.3.0 and later). If the connector is not authorized, the execution of the response builder will be delayed up to the point of the callback execution.

On the other hand if the connector has been authorized and you call authorize again then the flow execution will not stop, it will rather continue and the http:response-builder will get executed right away rather than after the callback.

The following is an example of the authorize message processor, after which it will print the access token identifier to the log:

    <flow name="authorizationAndAuthenticationFlow">
        <http:inbound-endpoint host="localhost" port="8080" path="oauth-authorize"/>
        <google-tasks:authorize/>
		<log level="INFO" message="The connector has been properly authorized. The access token identifier is #[flowVars['OAuthAccessTokenId']]"/>
    </flow>

The OAuthAccessTokenId flow variable is a special variable available to all the message processors executing after the authorize call. The following snippet shows how you can save it as a HTTP protocol cookie:

    <flow name="authorizationAndAuthenticationFlow">
        <http:inbound-endpoint host="localhost" port="8080" path="oauth-authorize"/>
        <google-tasks:authorize/>
        <http:response-builder status="200">
            <http:set-cookie name="accessTokenId" value="#[flowVars['OAuthAccessTokenId']]"/>
            <set-payload value="You have successfully authorized the connector. You access token id is #[flowVars['OAuthAccessTokenId']]"/>
        </http:response-builder>
    </flow>

The access token identifier is unique per user and therefore the connector can be authorized for many users. If the user authorizes the connector twice it will have the same access token identifier both times.

Error Handling during Authorization

If for any reason, an errors ocurrs while processing the callback, the exception strategy of the flow containing the authorize will be executed. So, if the callback sent the wrong information you can handle that situation by setting up an exception strategy as follows:

  <flow name="authorizationAndAuthenticationFlow">
      <http:inbound-endpoint host="localhost" port="8080" path="oauth-authorize"/>
      <google-tasks:authorize/>
      <http:response-builder status="200">
          <set-payload value="You have successfully authorized the connector"/>
      </http:response-builder>
      <catch-exception-strategy>
         <http:response-builder status="404">
             <set-payload value="An error has occurred authorizing the connector"/>
         </http:response-builder>
      </catch-exception-strategy>
  </flow>

Unauthorize

Once this connector has been authorized further calls to the authorize message processor will be no-ops. If you wish to reset the state of the connector back to a non-authorized state you can call:

    <google-tasks:unauthorize/>

Keep in mind that after the connector is unauthorized all future calls that attempt to access protected resources will fail until the connector is re-authorized.

Callback Customization

As mentioned earlier once authorize gets called and before we redirect the user to the service provider we create a callback endpoint. The callback endpoint will get called automatically by the service provider once the user is authenticated and he grants authorization to the connector to access his private information.

The callback can be customized in the config element of the this connector as follows:

    <google-tasks:config>
        <google-tasks:oauth-callback-config domain="${fullDomain}" localPort="${http.port}" remotePort="80"/>
    </google-tasks:config>

The oauth-callback-config element can be used to customize the endpoint that gets created for the callback. It features the following attributes:

OAuth Callback Config Attributes
NameDescription
connector-ref Optional. Reference to a user-defined HTTP connector.
domain Optional. The domain portion of the callback URL. This is usually something like xxx.cloudhub.io if you are deploying to CloudHub for example.
localPort Optional. The local port number that the endpoint will listen on. Normally 80, in the case of CloudHub you can use the environment variable ${http.port}.
remotePort Optional. This is the port number that we will tell the service provider we are listening on. It is usually the same as localPort but it is separated in case your deployment features port forwarding or a proxy.
path Optional. Path under which the callback should be exposed. If not specified a random path will be generated.

The example shown above is what the configuration would look like if your app would be deployed to CloudHub.

Access Token Store

This connector has the capability of automatically saving and restoring access tokens. The connector will store in either the default user object store or a user-defined one the acquired access tokens, refresh tokens, and any other pertinent information using the access token identifier as the key.

The object store can be configured as follows

    <google-tasks:config>
        <google-tasks:oauth-store-config objectStore-ref="my-object-store"/>
    </google-tasks:config>

There is only a single attribute entitled objectStore-ref in the oauth-store-config element that allows the user to specify the name of the object store that he wishes to use to save and restore access tokens.

Message Processors

<google-tasks:clear-tasks>

Clears all completed tasks from the specified task list. The affected tasks will be marked as 'hidden' and no longer be returned by default when retrieving all tasks for a task list.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
taskListId @default Optional. Task list identifier String */* UTF-8
OAuth Parameters
The following values are always required when using OAuth as the authentication mechanism.
accessTokenId Access token identifier used to retrieve an access token from the store
Exception Payloads
Payload ClassDescription
IOException if there's an error in the communication

<google-tasks:delete-task>

Deletes the specified task from the task list.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
taskListId @default Optional. Task list identifier String */* UTF-8
taskId Task identifier. String */* UTF-8
OAuth Parameters
The following values are always required when using OAuth as the authentication mechanism.
accessTokenId Access token identifier used to retrieve an access token from the store
Exception Payloads
Payload ClassDescription
IOException if there's an error in the communication

<google-tasks:delete-task-list>

Deletes the authenticated user's specified task list.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
taskListId @default Optional. Task list identifier. String */* UTF-8
OAuth Parameters
The following values are always required when using OAuth as the authentication mechanism.
accessTokenId Access token identifier used to retrieve an access token from the store
Exception Payloads
Payload ClassDescription
IOException if there's an error in the communication

<google-tasks:get-task-by-id>

Returns the specified task.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
taskListId @default Optional. Task list identifier String */* UTF-8
taskId Task identifier String */* UTF-8
OAuth Parameters
The following values are always required when using OAuth as the authentication mechanism.
accessTokenId Access token identifier used to retrieve an access token from the store
Returns
Return Type Description
Task an instance of Task
Exception Payloads
Payload ClassDescription
IOException if there's an error in the communication

<google-tasks:get-task-list-by-id>

Returns the authenticated user's specified task list

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
taskListId @default Optional. Task list identifier. String */* UTF-8
OAuth Parameters
The following values are always required when using OAuth as the authentication mechanism.
accessTokenId Access token identifier used to retrieve an access token from the store
Returns
Return Type Description
TaskList an instance of TaskList
Exception Payloads
Payload ClassDescription
IOException if there's an error in the communication

<google-tasks:get-task-lists>

Returns all the authenticated user's task lists. For supporting google's paging mechanism, the next page token is store on the message property "GoogleTask_NEXT_PAGE_TOKEN". If there isn't a next page, then the property is removed

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
message The current mule message MuleMessage */*
maxResults 100 Optional. Maximum number of task lists returned on one page long */*
pageToken Optional. Token specifying the result page to return String */* UTF-8
OAuth Parameters
The following values are always required when using OAuth as the authentication mechanism.
accessTokenId Access token identifier used to retrieve an access token from the store
Returns
Return Type Description
List<TaskList> a list with instances of TaskList
Exception Payloads
Payload ClassDescription
IOException if there's an error in the communication

<google-tasks:get-tasks>

Returns all tasks in the specified task list. This method accepts a number of filtering attributes. The one for which no values is specified will not be used when filtering For supporting google's paging mechanism, the next page token is store on the message property "GoogleTask_NEXT_PAGE_TOKEN". If there isn't a next page, then the property is removed

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
message The current mule message MuleMessage */*
taskListId @default Optional. Task list identifier String */* UTF-8
completedMin Optional. Lower bound for a task's completion date (as a RFC 3339 timestamp) to filter by String */* UTF-8
completedMax Optional. Upper bound for a task's completion date (as a RFC 3339 timestamp) to filter by String */* UTF-8
dueMin Optional. Lower bound for a task's due date (as a RFC 3339 timestamp) to filter by String */* UTF-8
dueMax Optional. Upper bound for a task's due date (as a RFC 3339 timestamp) to filter by String */* UTF-8
updatedMin Optional. Lower bound for a task's last modification time (as a RFC 3339 timestamp) to filter by String */* UTF-8
maxResults 100 Optional. Maximum number of task lists returned on one page long */*
pageToken Optional. Token specifying the result page to return String */* UTF-8
showDeleted false Optional. Flag indicating whether deleted tasks are returned in the result boolean */*
showHidden false Optional. Flag indicating whether hidden tasks are returned in the result boolean */*
showcompleted false Optional. Flag indicating whether completed tasks are returned in the result boolean */*
OAuth Parameters
The following values are always required when using OAuth as the authentication mechanism.
accessTokenId Access token identifier used to retrieve an access token from the store
Returns
Return Type Description
List<Task> list with instances of Task
Exception Payloads
Payload ClassDescription
IOException if there's an error in the communication

<google-tasks:insert-task>

Creates a new task on the specified task list

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
taskListId @default Optional. Task list identifier String */* UTF-8
task #[payload:] Optional. Instance of Task containing the state of the task to be inserted Task */*
OAuth Parameters
The following values are always required when using OAuth as the authentication mechanism.
accessTokenId Access token identifier used to retrieve an access token from the store
Returns
Return Type Description
Task instance of Task representing the state of the newly inserted task
Exception Payloads
Payload ClassDescription
IOException if there's an error in the communication

<google-tasks:insert-task-list>

Creates a new task list and adds it to the authenticated user's task lists.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
taskList #[payload:] Optional. The taskList to be inserted TaskList */*
OAuth Parameters
The following values are always required when using OAuth as the authentication mechanism.
accessTokenId Access token identifier used to retrieve an access token from the store
Returns
Return Type Description
TaskList an instance of TaskList representing the newly inserted task list
Exception Payloads
Payload ClassDescription
IOException if there's an error in the communication

<google-tasks:move>

Moves the specified task to another position in the task list. This can include putting it as a child task under a new parent and/or move it to a different position among its sibling tasks.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
taskListId @default Optional. Task list identifier String */* UTF-8
taskId Identifier for the task being moved. String */* UTF-8
parentId Optional. Parent task identifier. If the task is created at the top level, this parameter is omitted String */* UTF-8
previousId Optional. New previous sibling task identifier. If the task is moved to the first position among its siblings, this parameter is omitted String */* UTF-8
OAuth Parameters
The following values are always required when using OAuth as the authentication mechanism.
accessTokenId Access token identifier used to retrieve an access token from the store
Returns
Return Type Description
Task an instance of Task representing the state of the moved task
Exception Payloads
Payload ClassDescription
IOException if there's an error in the communication

<google-tasks:update-task>

Updates the specified task.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
taskListId @default Optional. Task list identifier String */* UTF-8
taskId Task identifier. String */* UTF-8
task #[payload:] Optional. Instance of Task containing the state we want the updated task to have Task */*
OAuth Parameters
The following values are always required when using OAuth as the authentication mechanism.
accessTokenId Access token identifier used to retrieve an access token from the store
Returns
Return Type Description
Task an instance of Task representing the state of the updated task
Exception Payloads
Payload ClassDescription
IOException if there's an error in the communication

<google-tasks:update-task-list>

Updates the authenticated user's specified task list.

XML Sample
INCLUDE_ERROR

Attributes
NameDefault ValueDescriptionJava TypeMIME TypeEncoding
config-ref Optional. Specify which configuration to use.
taskList #[payload:] Optional. An instance of TaskList with the task list's new state TaskList */*
taskListId @default Optional. Task list identifier String */* UTF-8
OAuth Parameters
The following values are always required when using OAuth as the authentication mechanism.
accessTokenId Access token identifier used to retrieve an access token from the store
Returns
Return Type Description
TaskList an instance of TaskList representing the state of the updated list
Exception Payloads
Payload ClassDescription
IOException if there's an error in the communication

Message Sources

Transformers