-
-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct way to put credentials.json directly into .env variable #68
Comments
Thanks! Yes I tried with single quotes and laravel works, but then I receive a certificate error when the package connects to google. "Invalid service account: json_decode error: Control character error, possibly incorrectly encoded" It’s useful to know that it’s working for you like that. Now I’ll need to figure out what’s different in my system. |
Which versions of Laravel, the SDK and the package are you using? Also, can you ensure that nothing is escaped in the minified JSON except the line breaks inside the private key? My JSON looks like this:
|
Thanks - sorry for slow weekend response. Laravel 6.18.35 Here are the credentials
here is the network error from the browser: and here is the error from the logs:
Just to note again - everything works great locally if i just reference the json file directly. I know troubleshooting things like this takes time so thanks in advance for your help!!! |
Thanks for sharing the additional info! I haven't been able to test this yet, but I am (sadly) quite confident that it could have something to do with the used Laravel bein on version 6, perhaps the DotEnv component within is not as capable as in newer Laravel versions. But this is just a guess, I will try to replicate this later tonight 🤞 |
Thanks so much for your help!!
If it’s a laravel version issue - at least I’ll know my options.
…On Nov 10, 2020, 14:15 -0500, Jérôme Gamez ***@***.***>, wrote:
Thanks for sharing the additional info! I haven't been able to test this yet, but I am (sadly) quite confident that it could have something to do with the used Laravel bein on version 6, perhaps the DotEnv component within is not as capable as in newer Laravel versions.
But this is just a guess, I will try to replicate this later tonight 🤞
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Sorry again for the late reply, but I wanted to make sure I test this with enough time. Here's what I did (on a Mac with PHP 7.4.12): $ composer create-project "laravel/laravel:6.18.35" laravel6
$ cd laravel6
$ composer require "kreait/laravel-firebase:^2.0"
$ jq -c . < /path/to/firebase_service_account.json | pbcopy
# Add the clipboard contents into the .env file
# so that it has FIREBASE_CREDENTIALS='<clipboard_content>' and, alas, I got the same error 😩: $ php artisan tinker
Psy Shell v0.10.4 (PHP 7.4.12 — cli) by Justin Hileman
>>> app('firebase.database')
Kreait/Firebase/Exception/InvalidArgumentException with message 'Invalid service account: json_decode error: Control character error, possibly incorrectly encoded' I assume this has something to do with the required version of However, here's something that worked on my machine with Laravel 6, and I hope it works for you as well: First, if you haven't already done it, publish the package configuration with $ php artisan vendor:publish --provider="Kreait\Laravel\Firebase\ServiceProvider" --tag=config Then, in
to
This will remove all control characters from the string (I assume the linebreaks are what killed it) and worked on my machine™ 🤞 |
Thanks for your work on this!! Wow that was helpful. First, that did not work for me. However I did find another solution below. I published the config, made your suggested changes, and then recompressed the file. I got a different error - the openssl_sign error - which i had previously gotten when messing with the spaces in the key.
However, your comment about vlucas/phpdotenv versions made me fine my way to this solution which recommended enclosing the slashes like this:
And it works!! I rewound all the other modifications and just left the config file alone. Here is a recap for anyone else finding this:
Your help on this was great. Maybe this will be useful to someone down the line. Thanks! |
@chuckienorton @jeromegamez thanks guys, that worked with me too! but i got another problem i hope to help me with it as i am fresher to deal with firebase
` openssl_sign(): supplied key param cannot be coerced into a private key thanks! |
Leaving comment for future researcher:
Somehow it's no longer needed now. I only need to jq it and paste it directly (with single quote of course) to .env file. And it's working :D |
Somehow it's no longer needed now. I only need to jq it and paste it directly (with single quote of course) to .env file. And it's working :D |
This excellent package works great for me when referencing the credentials via file in the .env file. However, we use Heroku for staging/production and only have access to string environment variables.
Following this closed issue #63
I used JQ to minify my file, and then placed it into the .env like this:
FIREBASE_CREDENTIALS={"type":"service_account","project_id" ...
This works without the private key, but with the full json which includes '"private_key":"-----BEGIN PRIVATE KEY-----\n' it throws the following laravel application error: "Failed to parse dotenv file due to unexpected whitespace."
If i enclose the entire thing in apostrophes like this:
FIREBASE_CREDENTIALS='{"type":"service_account","project_id" ... '
I get the following error: "Invalid service account: json_decode error: Control character error, possibly incorrectly encoded"
If i remove the apostrophes so the json can correctly decode, and then attempt to change the private key at all - escaping the spaces or anything like this:
FIREBASE_CREDENTIALS={"type":"service_account","private_key":"-----BEGIN\ PRIVATE\ KEY-----\
i get the following error response when trying to use the service: "openssl_sign(): supplied key param cannot be coerced into a private key",…}"
What is the correct format for the FIREBASE_CREDENTIALS variable?
Thanks in advance!!
The text was updated successfully, but these errors were encountered: