spatie / laravel-google-cloud-storage

Google Cloud Storage filesystem driver for Laravel
https://spatie.be/open-source
MIT License
196 stars 51 forks source link

Google Cloud ADC Authentication OS Environment Variable Not Working #75

Closed Cooper-Wang49 closed 1 year ago

Cooper-Wang49 commented 1 year ago

Discussed in https://github.com/spatie/laravel-google-cloud-storage/discussions/74

Originally posted by **Cooper-Wang49** November 6, 2023 I'm using ADC authentication, but GOOGLE_APPLICATION_CREDENTIALS doesn't read the environment variables at the OS level ```log [previous exception] [object] (Google\\Cloud\\Core\\Exception\\ServiceException(code: 401): {\"error\":{\"code\":401,\"message\":\"Invalid Credentials\",\"errors\":[{\"message\":\"Invalid Credentials\",\"domain\":\"global\",\"reason\":\"authError\",\"locationType\":\"header\",\"location\":\"Authorization\"}]}} at /var/www/html/vendor/google/cloud-core/src/RequestWrapper.php:398) ``` environment: PHP version: 8.1.24 Laravel version: 9.52.16 spatie/laravel-google-cloud-storage : 2.2.3 `docker-compose.yml` ```yaml services: laravel.test: build: context: ./vendor/laravel/sail/runtimes/8.1 dockerfile: Dockerfile args: WWWGROUP: "${WWWGROUP}" image: sail-8.1/app environment: GOOGLE_APPLICATION_CREDENTIALS: "/run/gcp_adc.json" volumes: - ".:/var/www/html" - $HOME/.config/gcloud/application_default_credentials.json:/run/gcp_adc.json:ro ``` My Solution: Add the following to the .env file ``` GOOGLE_APPLICATION_CREDENTIALS="/run/gcp_adc.json ``` now it's work
freekmurze commented 1 year ago

Let's leave it in the discussion.