clasp icon indicating copy to clipboard operation
clasp copied to clipboard

"No access, refresh token, API key or refresh handler callback is set." error on login

Open ypresto opened this issue 2 years ago • 2 comments

I followed this instruction. https://github.com/google/clasp/blob/551000b55565d20fccc29673c5460022d42ee5cf/docs/run.md

When I npx clasp login --creds ./creds.json then click button in web, or npx clasp push, got error message but I have no idea why. I did some retries but no luck.

Expected Behavior

The error should not occur.

Actual Behavior

npx clasp login --creds ./creds.jso

...

Local credentials saved to: /Users/ypresto/repo/github.com-private/ypresto/asloop-survey/gas/.clasprc.json.
*Be sure to never commit this file!* It's basically a password.
No access, refresh token, API key or refresh handler callback is set.

then

$ npx clasp push
Could not read API credentials. Are you logged in globally?

Steps to Reproduce the Problem

  1. Followed steps in https://github.com/google/clasp/blob/551000b55565d20fccc29673c5460022d42ee5cf/docs/run.md
  • I used existing project, where npx clasp push is working with global login.
  • I created new GCP project.
  • I also added my google account to test user list of OAuth client.
  • I checked scriptId and projectId is correct.
  • The creds.json has just been downloaded from GCP.
  • The google account used for login is an owner of Google Forms which bound to the script.
  • I also tried removing global login (~/.clasprc.json) then retry, but nothing worked.
  1. npx claps push

Specifications

  • Node version (v16.15.1):
  • Version (clasp -v): 2.4.2
  • OS (Mac/Linux/Windows): macOS 12.0.1

ypresto avatar Mar 18 '23 13:03 ypresto

TL;DR; from my experience: make sure you have a deployment of the latest code version that is an API executable accessible by anyone [with Google Account]

Detail: I experienced this same issue based on the following circumstances:

  1. Deployed project as API executable (anyone with Google account can access) Followed clasp run instructions, operated as expected

  2. Deployed new version as Add On (anyone within domain can access) Attempted clasp run, received the errors described in this issue

    This had changed my appsscript.json file to include the following:

    "executionApi": {
      "access": "DOMAIN"  // should be "ANYONE"
    }    
    
  3. Edited API executable deployment to use the latest version of the code Ran clasp run again, working again as intended

michaelconan avatar Dec 16 '23 00:12 michaelconan

I'm having what I think is a similar issue. I've created a .clasprc.json with npx clasp login --creds creds.json. I can run functions with clasp_config_auth=.clasprc.json npx clasp run myFunction, but I can't push code, list versions, deployments or use other Clasp functions. Examples below:

$ clasp_config_auth=.clasprc.json npx clasp run myFunction
Running in dev mode.
Hello, world!

$ clasp_config_auth=.clasprc.json npx clasp versions      
No access, refresh token, API key or refresh handler callback is set.

My .clasprc.json looks like:

{
    "token": {
        "access_token": "removed",
        "refresh_token": "removed",
        "scope": "https://www.googleapis.com/auth/script.projects https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/script.container.ui https://www.googleapis.com/auth/script.deployments https://www.googleapis.com/auth/logging.read https://www.googleapis.com/auth/script.external_request https://www.googleapis.com/auth/script.webapp.deploy https://www.googleapis.com/auth/script.scriptapp https://www.googleapis.com/auth/service.management https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/drive.metadata.readonly https://www.googleapis.com/auth/script.send_mail",
        "token_type": "Bearer",
        "expiry_date": 1703733471612
    },
    "oauth2ClientSettings": {
        "clientId": "removed",
        "clientSecret": "removed",
        "redirectUri": "http://localhost"
    },
    "isLocalCreds": true
}

Any ideas what could be happening here?

jcconnell avatar Dec 28 '23 02:12 jcconnell