Closed7

GitHub EnvでGCPのprivate_keyを渡したいだけなのに

Hiromichi ShiozukaHiromichi Shiozuka

Google Driveを使いたくて

    const client = new JWT({
      email: process.env.EMAIL,
      key: process.env. PRIVATE_KEY,
      scopes: this.SCOPES,
    });
    this.drive = google.drive({ version: 'v3', auth: client });

という感じで書いたら↓のエラー

Error: error:1E08010C:DECODER routines::unsupported
    at Sign.sign (node:internal/crypto/sig:131:29)
    at Object.sign (/node_modules/jwa/index.js:152:45)
    at Object.jwsSign [as sign] (/node_modules/jws/lib/sign-stream.js:32:24)
    at GoogleToken.requestToken (/node_modules/gtoken/build/src/index.js:224:31)
    at GoogleToken.getTokenAsyncInner (/node_modules/gtoken/build/src/index.js:158:21)
    at GoogleToken.getTokenAsync (/node_modules/gtoken/build/src/index.js:137:55)
    at GoogleToken.getToken (/node_modules/gtoken/build/src/index.js:96:21)
    at JWT.refreshTokenNoCache (/node_modules/google-auth-library/build/src/auth/jwtclient.js:172:36)
    at JWT.refreshToken (/node_modules/google-auth-library/build/src/auth/oauth2client.js:154:24)
    at JWT.getRequestMetadataAsync (/node_modules/google-auth-library/build/src/auth/oauth2client.js:299:28)
Hiromichi ShiozukaHiromichi Shiozuka

Firebase Adminの admin.initializeApp

FirebaseAppError: Failed to parse private key: Error: Invalid PEM formatted message.
Hiromichi ShiozukaHiromichi Shiozuka

現状: localでは何も対応しなくても動いている

.env
GCP_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n..............\n-----END PRIVATE KEY-----\n"
client.ts
    const client = new JWT({
      email: process.env.EMAIL,
      key: process.env.GCP_PRIVATE_KEY,
      scopes: this.SCOPES,
    });
Hiromichi ShiozukaHiromichi Shiozuka

GitHubのenvironmentに設定するときに

"-----BEGIN PRIVATE KEY-----\n..............\n-----END PRIVATE KEY-----\n" と入れるのではなくて

-----BEGIN PRIVATE KEY-----\n..............\n-----END PRIVATE KEY-----\n と入れるようにしたら解決

(+ .replace(/\\n/g, '\n') )

このスクラップは6ヶ月前にクローズされました