- πΊπΈUnited States pwolanin
duplicate to π Simplify module config and constructor for JwtTranscoder Fixed
The constructor for \Drupal\jwt\Transcoder\JwtTranscoder hard-codes the config name and makes it more difficult than necessary to instantiate this class for use with different keys.
Also, class \Drupal\jwt\Transcoder\JwtTranscoder is also not really ideal for use as a service since it's mutable via methods like setSecret()
It seems you could have a much simplified constructor.
For example:
public function __construct(KeyInterface $key) {
$this->transcoder = new JWT();
$keyConfig = $key->getPlugin('key_type')->getConfiguration();
$algorithm = $keyConfig['algorithm'];
$this->setAlgorithm($algorithm);
$key_value = $key->getKeyValue();
if (!empty($key_value)) {
if ($this->algorithmType == 'jwt_hs') {
// Symmetric algorithm so we set the secret.
$this->setSecret($key_value);
}
elseif ($this->algorithmType == 'jwt_rs') {
// Asymmetric algorithm so we set the private key.
$this->setPrivateKey($key_value);
}
}
}
The JWT class from the library only has static methods - I'm not sure why you are even instantiating it or providing it as a service?
Possibly there could be a new base class with a simple constructor and the existing class changed to a subclass?
Decide on what's the right approach
n/a
n/a
Closed: outdated
1.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
duplicate to π Simplify module config and constructor for JwtTranscoder Fixed