oCredentials: An intro
Introduction
When we need to store a user/pass or an auth token of a third-party service, we can use credentials to do so rather than storing them in an .env.
Credentials (oCredentials) are objects that can have one or more credential items (oCredentialItems). Each credential item is typed (oCredentialTypes). If you needed to store a username and password for a given provider, you would create one credential and two credential items, one for username and one for password, creating credential types for each one if not already found in the oCredentialTypes table.
Creating a new credential
-
Create a new credential
Open your favorite database management application and open the
hqdatabase. Create a new entry inoCredentialsmaking sure you enter in a descriptive name and description. Write down the ID of your new credential as you’ll need it in the last step. -
Create any necessary credential types
If you don’t see any types in the
oCredentialTypestable, go ahead and create new entries following the structure of the other entries in that table now. Write down the ID(s) of the types that you will be using as you’ll need them in the next step. -
Create your credential items
You’ll need to use tinker for this step, so jump into the hq docker container and then load tinker.
docker exec -ti hq bash # Start up Tinker php artisan tinkerOnce tinker is up, run the following:
# Create new credential item $credItem = new hq\eloquent\Credentials\CredentialItem; # This is the oCredentialTypes ID. Replace '10' with the relevant type ID. $credItem->type_id = 10; # This is the oCredential ID. Replace '7' with your credential ID. $credItem->credential_id = 7; # This is the user/pass/token/etc that needs stored $credItem->value = 'supersecurepassword'; # Save it $credItem->save();That’s it!
-
Bonus step
If you changed
__ENVIRONMENT__toPRODUCTIONin yourmalouf-settings.phpfile, be sure to change it back toDEVELOPMENT!