{"action":"closed","issue":{"url":"https://api.github.com/repos/googlesamples/apps-script-oauth2/issues/51","repository_url":"https://api.github.com/repos/googlesamples/apps-script-oauth2","labels_url":"https://api.github.com/repos/googlesamples/apps-script-oauth2/issues/51/labels{/name}","comments_url":"https://api.github.com/repos/googlesamples/apps-script-oauth2/issues/51/comments","events_url":"https://api.github.com/repos/googlesamples/apps-script-oauth2/issues/51/events","html_url":"https://github.com/googlesamples/apps-script-oauth2/issues/51","id":187173966,"number":51,"title":"Token expires when I call OAuth in an external library","user":{"login":"FirePanther","id":1711106,"avatar_url":"https://avatars.githubusercontent.com/u/1711106?v=3","gravatar_id":"","url":"https://api.github.com/users/FirePanther","html_url":"https://github.com/FirePanther","followers_url":"https://api.github.com/users/FirePanther/followers","following_url":"https://api.github.com/users/FirePanther/following{/other_user}","gists_url":"https://api.github.com/users/FirePanther/gists{/gist_id}","starred_url":"https://api.github.com/users/FirePanther/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FirePanther/subscriptions","organizations_url":"https://api.github.com/users/FirePanther/orgs","repos_url":"https://api.github.com/users/FirePanther/repos","events_url":"https://api.github.com/users/FirePanther/events{/privacy}","received_events_url":"https://api.github.com/users/FirePanther/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-03T19:57:55Z","updated_at":"2016-11-04T20:45:51Z","closed_at":"2016-11-04T20:45:51Z","body":"I have a local gs script with the functions 'run' and 'authCallbackTest' and an external gs script with the OAuth itself (OAuth2.createService...).\r\nThe local gs script includes the external gs script via 'Libraries...'.\r\nThe token will be created successfully (with param access_type 'offline') but expires after an hour.\r\nWhen I put the external code (the createService part) into the internal code it can be refreshed without expiration.\r\n\r\nscript 1 (internal)\r\n```javascript\r\n// token generated: 19:53\r\n// expired in 20:53, just tested\r\n\r\nfunction run() {\r\n  var service = test.getContactsService(opts());\r\n  if (!service.hasAccess()) {\r\n    var authorizationUrl = service.getAuthorizationUrl();\r\n    Logger.log('open link:');\r\n    Logger.log(authorizationUrl);\r\n    throw 'Expired';\r\n  } else {\r\n    Logger.log('Everything is fine');\r\n  }\r\n}\r\n\r\nfunction authCallbackTest(request) {\r\n\tvar service = test.getContactsService(opts());\r\n\ttry {\r\n\t\tif (service.handleCallback(request)) return HtmlService.createHtmlOutput('success');\r\n\t\telse return HtmlService.createHtmlOutput('denied');\r\n\t} catch(e) {\r\n\t\treturn HtmlService.createHtmlOutput(e);\r\n\t}\r\n}\r\n\r\nfunction opts() {\r\n  return {\r\n    clientId: '...',\r\n    clientSecret: '...'\r\n  };\r\n}\r\n```\r\n\r\nscript 2 \"test\" (external)\r\n```javascript\r\nfunction getContactsService(opt) {\r\n\topt = opt || this.options;\r\n\treturn OAuth2.createService('contacts')\r\n\t\t.setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')\r\n\t\t.setTokenUrl('https://accounts.google.com/o/oauth2/token')\r\n\t\t.setClientId(opt.clientId)\r\n\t\t.setClientSecret(opt.clientSecret)\r\n\t\t.setCallbackFunction('authCallbackTest')\r\n\t\t.setPropertyStore(PropertiesService.getUserProperties())\r\n\t\t.setScope('https://www.google.com/m8/feeds')\r\n\t\t.setParam('login_hint', Session.getActiveUser().getEmail())\r\n\t\t.setParam('access_type', 'offline')\r\n\t\t.setParam('approval_prompt', 'auto');\r\n}\r\n```"}}
{"actor":{"display_login":"erickoledadevrel"}}