Best way to store Joomla API token when using Web Services Topic is solved

Need help with the Administration of your Joomla! 5.x site? This is the spot for you.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Post Reply
davidascher
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 135
Joined: Tue Feb 28, 2006 3:23 pm

Best way to store Joomla API token when using Web Services

Post by davidascher » Wed Mar 27, 2024 3:33 pm

Is there a recommended 'best practice' for how to store a Joomla API token when using it to access a site via the Web Services API?
Last edited by toivo on Thu Mar 28, 2024 1:34 am, edited 1 time in total.
Reason: mod note: moved, not related to 5.x Security

davidascher
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 135
Joined: Tue Feb 28, 2006 3:23 pm

Re: Best way to store Joomla API token when using Web Services

Post by davidascher » Thu Mar 28, 2024 12:08 am

Maybe this will clarify my question? I don't want to put my Joomla API token into code in plain text for security reasons. What is a secure way to store the token but be able to retrieve it for a call to the Webservices API?

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24986
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Best way to store Joomla API token when using Web Services

Post by pe7er » Thu Mar 28, 2024 12:25 pm

davidascher wrote:
Thu Mar 28, 2024 12:08 am
I don't want to put my Joomla API token into code in plain text for security reasons.
When you use a PHP script that needs to access your Joomla API, it needs an API token.
You can make that token available via an .env file that you load and read into the PHP.
That way, it is not available as plain text in the PHP script.
But it is still stored in the same place as the PHP script.
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

davidascher
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 135
Joined: Tue Feb 28, 2006 3:23 pm

Re: Best way to store Joomla API token when using Web Services

Post by davidascher » Thu Mar 28, 2024 9:05 pm

Thank you. I'm using
$env = parse_ini_file('.env');
$token = $env["token"];

It's simple and quick - and I guess it is as secure as .env is.

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24986
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Best way to store Joomla API token when using Web Services

Post by pe7er » Fri Mar 29, 2024 8:09 am

You're welcome!

Yeah, that way the API key is not displayed in your .php file anymore (and not displayed when you show your code to someone else).
Furthermore you can add it to .gitignore so that it won't be committed to an external git repository.
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com


Post Reply

Return to “Administration Joomla! 5.x”