App platform store Laravel Passport keys as variable

I have deployed Laravel app with passport authentication on DigitalOcean App Platform. The problem occur when the app gets deployed again and I need to generate new passport keys (php artisan passport:install). Is there a way to store those two files (oaut-private.key and oauth-public.key) as environment variables? I am new to this and I don’t really know how it works… Thanks for help!

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

👋🏼 @brackog

Please let me know if I misunderstood your question, but I believe you can achieve this like so:

First, store the files’ contents in env vars and make sure to check the “Encrypt” box

  1. Key: PASSPORT_OAUTH_PRIVATE_KEY Value: contents of oauth-private.key
  2. Key: PASSPORT_OAUTH_PUBLIC_KEY Value: contents of oauth-public.key

Then, update your app’s run command to first write the files using the content from the env vars and then start Laravel:

echo -n "$PASSPORT_OAUTH_PRIVATE_KEY" >storage/oauth-private.key
echo -n "$PASSPORT_OAUTH_PUBLIC_KEY" >storage/oauth-public.key

heroku-php-apache2 public/

The -n flag stops echo from adding a newline at the end of the file in case that affects Laravel Passport.