Change from project key to scriptid

The Apps Script Script service is deprecating the getProjectKey() method. At this time it’s not clear when or why, but it does mean that if you are using the project key to create Oauth2 redirect URLs (and most people are), then that’ll need to be changed sometime.

I don’t know the timetable for the project key to go away, and any already active token environments will continue to work as is, until it does. This post mainly concerns the cGoa library which many of you are using to manage OAuth2 dialogs with Apps Script. Service account flows are not affected,  since they don’t use redirectUrls, and neither is my VBA library for OAuth2 from Excel. So this only applies to Apps Script webapp flows.

The changes you’ll need to make are.

  • Use the latest version the Goa library (22 or above), which has been updated to use the scriptId rather than the project key.
  • Re-run your oneoff credentials function to invalidate your current token environment and provoke a new one.
  • Re-run your app and you’ll get a new auth dialog, which looks as below. It’s exactly the same as the old dialog, except that the redirect URI is now using the scriptId instead of the project Key. You can just copy and paste this into the redirect URI of your console project. I recommend that you add to your console and leave the old project key redirect there too. That way both will work for as long as the project key still does.


A couple of tips.
  • If you can’t remember what console project you used for a project (we’ve all been there), then just let it run without updating the console project. It will fail, and give you a link to the console project which you can use to access the redirect url page that needs changing.
  • If you don’t have your credentials handy, then you can invalidate the current oauth2 refresh environment with something like this. This will provoke a new authorization dialog.

 cGoa.GoaApp.invalidate(PropertiesService.getScriptProperties(), packageName);

 

About brucemcp 225 Articles
I am a Google Developer Expert and decided to investigate Google Apps Script in my spare time. The more I investigated the more content I created so this site is extremely rich. Now, in 2019, a lot of things have disappeared or don’t work anymore due to Google having retired some stuff. I am however leaving things as is and where I came across some deprecated stuff, I have indicated it. I decided to write a book about it and to also create videos to teach developers who want to learn Google Apps Script. If you find the material contained in this site useful, you can support me by buying my books and or videos.