Repost: oAuth 2 (Google) and CFML without cfoauth

Repost: oAuth 2 (Google) and CFML without cfoauth

Hopefully, this will save someone a bunch of time. This is a very simple example of how to do oAuth 2 (in this case, with Google) in CFML without using ACF 11's new oauth tag:

1-time steps:

Use https://console.developers.google.com to add a new Project and then a new Client ID for native application.

Get your code by using your browser to visit:

https://accounts.google.com/o/oauth2/auth?scope=[urlencodedformat of API's scope from API's docs]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=[client ID from above]

Get your refresh_token by dumping the results of this cfhttp:

result:

{
"access_token" : "[an access token]",
"token_type" : "Bearer",
"expires_in" : 3600,
"refresh_token" : "[your refresh token]"
}

[end of 1-time steps]

Now that you have your refresh token (which should not change), you can use it whenever you need a new access token, as follows:

...and then use it in your API calls, like this:

Enjoy!