<ConnectionManager xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="Zoom" RuntimeVersion="" Help="http://www.cozyroc.com/ssis/zoom-connection" xmlns="http://www.cozyroc.com/schema/rcm-config-1.0.xsd">
	<Service EndPoint="https://api.zoom.us/v2" />
	<Authentication Name="OAuth 2">
		<Documentation>https://marketplace.zoom.us/docs/guides/authorization/oauth/oauth-with-zoom</Documentation>
		<User>
			<Parameter Name="Scope" Default="account:master billing:master contact:read:admin dashboard:master group:master imchat:write:admin imgroup:master meeting:master pac:master recording:master report:master report:read:admin role:master room:master scim2 sip_phone:master sip_trunk:master tracking_fields:master tsp:master user:master user:read:admin webinar:master" />
		</User>
		<Test Url="/users/me" />
		<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="{{=
				connection.execute({
					url: OAuth2.authorization_url,
					method: OAuth2.authorization_method,
					headers: { Authorization: 'Basic ' + Base64.encode(OAuth2.client_id + ':' + OAuth2.client_secret) },
					parameters: {
						code: response.code,
						grant_type: OAuth2.grant_type,
						redirect_uri: OAuth2.redirect_uri,
						scope: token.Scope
					}
				})}}">

				<Documentation>https://marketplace.zoom.us/docs/guides/authorization/oauth/oauth-with-zoom#step-2-request-access-token</Documentation>
			</Authorized>
			<Refresh Url="{{=OAuth2.refresh_token_url}}" Method="POST" Result="{{=response.refresh_token}}" Expiration="{{=Date.now() + (response.expires_in - 300) * 1000}}">
				<Documentation>https://marketplace.zoom.us/docs/guides/authorization/oauth/oauth-with-zoom#refreshing</Documentation>
				<Parameters>
					<Parameter Name="refresh_token" Value="{{=token.Refresh}}" />
					<Parameter Name="grant_type" Value="refresh_token" />
					<Parameter Name="Authorization" Value="Basic {{=Base64.encode(OAuth2.client_id + ':' + OAuth2.client_secret)}}" Type="HttpHeader" />
				</Parameters>
			</Refresh>
		</Token>
		<Parameters>
			<Parameter Name="Authorization" Value="Bearer {{=token.Access}}" 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="page_number" Value="{{=parameters.iterator}}" />
						<Parameter Name="page_size" Value="{{=parameters.batchSize}}" />
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
					</Parameters>
					<Iterator>
						<Next Value="{{=parseInt(parameters.iterator || 1) + 1}}" />
					</Iterator>
				</Read>
				<Create Method="POST">
					<Parameters>
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
						<Parameter Name="item" Value="{{=item}}" />
					</Parameters>
				</Create>
				<Update Method="PUT">
					<Parameters>
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
						<Parameter Name="item" Value="{{=item}}" />
					</Parameters>
				</Update>
				<Delete Method="DELETE" />
			</Resource>
		</Template>
	</Resources>
	<Script>
		<Module Name="Main">
			<![CDATA[
			require("underscore");
			require('base64');
]]>
		</Module>
		<Module Name="OAuth 2">
			<![CDATA[
			// See RFC 6749 (https://tools.ietf.org/html/rfc6749) for familiarizing with OAuth2 authorization flows-related terms and concepts
			var OAuth2 = {
			client_id: "gk5sREtmTGeAMcoRBsFOCg", // required. The Client ID.
			client_secret: "yf53dE8EtsppN5HF98ewvrqWT7miJqnQ", // required. The Client Secret.
			sign_in_url: "https://zoom.us/oauth/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://zoom.us/oauth/token", // 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://zoom.us/oauth/token" // required, if the authentication needs to support renewing access tokens
			};
]]>
		</Module>
	</Script>
</ConnectionManager>