<ConnectionManager Name="MYOB" RuntimeVersion="" Help="http://www.cozyroc.com/ssis/myob-connection" xmlns="http://www.cozyroc.com/schema/rcm-config-1.0.xsd">
	<Service EndPoint="https://api.myob.com/accountright" />
	<Authentication Name="Basic">
		<Documentation>https://developer.myob.com/api/accountright/api-overview/authentication/</Documentation>
		<User>
			<Parameter Name="Username" />
			<Parameter Name="Password" Type="password" />
		</User>
		<Test Url="/" />
		<Parameters>
			<Parameter Name="Authorization" Value="Basic {{=Base64.encode(connection.user.Username + ':' + connection.user.Password)}}" Type="HttpHeader" />
			<Parameter Name="x-myobapi-version" Value="v2" />
		</Parameters>
	</Authentication>
	<Authentication Name="OAuth 2">
		<Documentation>https://developer.myob.com/api/accountright/api-overview/authentication/</Documentation>
		<User>
			<Parameter Name="Scope" Default="CompanyFile" />
			<Parameter Name="Username">
				<Documentation>Required. Specify company file user id.</Documentation>
			</Parameter>
			<Parameter Name="Password" Type="password">
				<Documentation>Required. Specify company file password.</Documentation>
			</Parameter>
		</User>
		<Test Url="/" />
		<Token Url="{{=OAuth2.sign_in_url}}" Result="{{=response.access_token}}">
			<Parameters>
				<Parameter Name="response_type" Value="{{=OAuth2.sign_in_response_type}}" />
				<Parameter Name="client_id" Value="{{=OAuth2.client_id}}" />
				<Parameter Name="redirect_uri" Value="{{=OAuth2.redirect_uri}}" />
				<Parameter Name="scope" Value="{{=token.Scope}}" />
			</Parameters>
			<Authorized Id="{{=OAuth2.redirect_uri}}" Result="{{=&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;connection.execute({&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;url: OAuth2.authorization_url,&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;method: OAuth2.authorization_method,&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;parameters: {&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;code: response.code,&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;grant_type: OAuth2.grant_type,&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;client_id: OAuth2.client_id,&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;client_secret: OAuth2.client_secret,&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;redirect_uri: OAuth2.redirect_uri,&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;&#x9;&#x9;scope: token.Scope&#xD;&#xA;&#x9;&#x9;&#x9;&#x9;} })&#xD;&#xA;&#x9;&#x9;&#x9;}}" />
			<Refresh Url="{{=OAuth2.refresh_token_url}}" Method="POST" Result="{{=response.refresh_token}}" Expiration="{{=Date.now() + (response.expires_in - 300) * 1000}}">
				<Parameters>
					<Parameter Name="client_id" Value="{{=OAuth2.client_id}}" />
					<Parameter Name="redirect_uri" Value="{{=OAuth2.redirect_uri}}" />
					<Parameter Name="refresh_token" Value="{{=token.Refresh}}" />
					<Parameter Name="grant_type" Value="refresh_token" />
					<Parameter Name="scope" Value="{{=token.Scope}}" />
				</Parameters>
			</Refresh>
		</Token>
		<Parameters>
			<Parameter Name="Authorization" Value="Bearer {{=token.Access}}" Type="HttpHeader" />
			<Parameter Name="x-myobapi-cftoken" Value="{{=Base64.encode(connection.token.Username + ':' + connection.token.Password)}}" Type="HttpHeader" />
			<Parameter Name="x-myobapi-key" Value="{{=OAuth2.client_id}}" Type="HttpHeader" />
			<Parameter Name="x-myobapi-version" Value="v2" Type="HttpHeader" />
		</Parameters>
	</Authentication>
	<Resources>
		<Template>
			<Field Name="ShortText" DataType="DT_WSTR" Length="255" />
			<Field Name="LongText" DataType="DT_WSTR" Length="1000" />
			<Field Name="DateTime" DataType="DT_DBTIMESTAMP" />
			<Resource Name="Base">
				<Read Result="{{=response}}">
					<Parameters>
						<Parameter Name="$top" Value="{{=parameters.batchSize}}" />
						<Parameter Name="$skip" Value="{{=parameters.iterator}}" />
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
					</Parameters>
					<Iterator>
						<Next Value="{{=parseInt(parameters.iterator || 0) + parameters.batchSize}}" />
					</Iterator>
				</Read>
				<Create Method="POST">
					<Parameters>
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
						<Parameter Name="application/json" Value="{{=item}}" Type="Body" />
					</Parameters>
				</Create>
				<Update Method="PUT">
					<Parameters>
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
						<Parameter Name="application/json" Value="{{=item}}" Type="Body" />
					</Parameters>
				</Update>
				<Delete Method="DELETE" />
			</Resource>
		</Template>
	</Resources>
	<Script>
		<Module Name="Main">
			<![CDATA[
require("underscore");

		]]>
		</Module>
		<Module Name="Basic">
			<![CDATA[
require("base64");

		]]>
		</Module>
		<Module Name="OAuth">
			<![CDATA[
// See RFC 6749 (https://tools.ietf.org/html/rfc6749) for familiarizing with OAuth2 authorization flows-related terms and concepts 
var OAuth2 = {
	client_id: "bkmv9ga2mfzgaf8bkhk5jtm3", // required. The Client ID.
	client_secret: "jf222bJfGdhrExbrJvTpZnfq", // required. The Client Secret.
	sign_in_url: "https://secure.myob.com/oauth2/account/authorize", // required. The starting endpoint in the authorization server. 
	sign_in_response_type: "code", // optional. The value for the "response_type" parameter in the initiating call. Usually "code", but can also be "token", "id_token".
	authorization_url: "https://secure.myob.com/oauth2/v1/authorize", // required. The endpoint for exchanging authorization code for an access token.
	authorization_method: "POST", // required. Usually the authorization URL is accessed via a POST request.
	redirect_uri: "https://www.cozyroc.com/oauth_callback", // required. The callback URL to be called after autherization. If the default value doesn't meet requirements, need to setup "Token.Authorized.LocalListenUrl".
	grant_type: "authorization_code", // optional. Can also be "client_credentials" or "password" (see https://auth0.com/docs/applications/reference/grant-types-available )
	refresh_token_url: "https://secure.myob.com/oauth2/v1/authorize" // required, if the authentication needs to support renewing access tokens
};

		]]>
		</Module>
	</Script>
</ConnectionManager>