I am storing users credentials for a 3rd party service in my database. When storing, these are cast to encrypted
as below:
protected $casts = [
'enabled' => 'boolean',
'token_is_valid' => 'boolean',
'service_username' => 'encrypted',
'service_password' => 'encrypted',
'service_practice_pin' => 'encrypted',,
];
I then need to use the details to authenticate with the 3rd party service.
I can return the full model from my database:
dd($integration)
, however if I try to access the propery dd($integration->service_username)
I get the below error:
The payload is invalid. {"userId":12,"exception":"[object] (Illuminate\\Contracts\\Encryption\\DecryptException(code: 0): The payload is invalid. at /var/www/app/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:221)
[stacktrace]
The 3rd party service I am using requires the decrypted values to authenticate.
I tried adding an accessor to the model but still get the same error
public function getDecryptedServiceUsernameAttribute()
{
return decrypt($this->attributes['service_username']);
}
How can I receive/send the decrypted value? Do I need to store it differently? current column type is varchar(191)