public function withValue() { $argc = func_num_args(); if ($argc == 1) { $this->mappingValue = func_get_arg(0); } else { if ($argc == 3) { $personal = func_get_arg(0); $kid = func_get_arg(1); $secret = func_get_arg(2); if (!isset($personal) || empty($kid) || empty($secret)) { throw new \InvalidArgumentException("Personal Object or kid or secret may be null."); } $json = json_encode($personal->__toArray()); // var_dump(JsonPrettyPrint::prettyPrint($json)); $jose = new Jose(); $this->mappingValue = $jose->configuration(JoseBuilders::JsonEncryptionCompactSerializationBuilder()->header(new JoseHeader(array(JoseHeaderSpec::ALG => Jwa::A256KW, JoseHeaderSpec::ENC => Jwa::A128CBC_HS256, JoseHeaderSpec::KID => $kid)))->payload($json)->key($secret))->serialization(); } else { throw new \InvalidArgumentException("Unknown parameter."); } } return $this; }
public function generateTokenBy($secret) { $jose = new Jose(); return $jose->configuration(JoseBuilders::JsonSignatureCompactSerializationBuilder()->header(new JoseHeader(array(JoseHeaderSpec::ALG => Jwa::HS256, JoseHeaderSpec::TYP => 'JWT', JoseHeaderSpec::KID => $this->iss)))->payload($this->toJson())->key($secret))->serialization(); }