I am using the CFC for the Google Calendar V3 API by billeatman. I have integrated it successfully in my pages, where I go to login and authenticate and start working. My trouble starts when the authentication expires, even when the session is still active in my website.
I tried storing the structure returned by the Google API along with the Access_token and refresh_token in the database table. After storing, I am just confused. How do I call it? The above GIT Code just says like this:
<cfset application.oauth2.refreshToken() />
The function has the following code:
<cffunction name="RefreshToken" access="public" output="false" hint="I take the refresh_token from the authorization procedure and get you a new access token.">
<cfset var strURL = base_auth_endpoint & "token">
<cfhttp url="#strURL#" method="POST">
<cfhttpparam name="client_id" type="formField" value="#variables.client_id#">
<cfhttpparam name="client_secret" type="formField" value="#variables.client_secret#">
<cfhttpparam name="refresh_token" type="formField" value="#getTokenStruct().refresh_token#">
<cfhttpparam name="grant_type" type="formField" value="refresh_token">
</cfhttp>
<cfreturn manageResponse(cfhttp.FileContent)>
</cffunction>
But I am lost about how I pass the token I stored in my database to refreshToken. So what I tried is, calling the following two functions:
<cfset application.oauth2.SetRefresh_token('#getaccess.refreshtoken#')>
<cfset application.oauth2.SetAccess_token('#getaccess.accesstoken#')>
An error is thrown at this section:
<cfset application.oauth2.SetAccess_token('#getaccess.accesstoken#')>
It says "Method not found in the CFC". I am lost. How do I keep the oauth2 alive for the google calendar, until I am logged out.
<cffunction name="SetAccess_token" access="private" output="false" hint="setter for oauth access_token">
<cfargument name="access_token" type="string" required="true">
<cfset getTokenStruct()['access_token'] = arguments.access_token>
</cffunction>
<cffunction name="SetRefresh_token" access="public" output="true" hint="setter for oauth refresh_token">
<cfargument name="refresh_token" type="string" required="true">
<cfset getTokenStruct()['refresh_token'] = arguments.refresh_token>
</cffunction>