1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xmf\Jwt;
13:
14: /**
15: * Build a token
16: *
17: * @category Xmf\Jwt\TokenFactory
18: * @package Xmf
19: * @author Richard Griffith <richard@geekwright.com>
20: * @copyright 2016 XOOPS Project (http://xoops.org)
21: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22: * @link http://xoops.org
23: */
24: class TokenFactory
25: {
26: /**
27: * Create a JSON Web Token string
28: *
29: * @param string $keyName name of the key to use to sign the token
30: * @param array|Traversable $payload traversable set of claims, claim => value
31: * @param int $expirationOffset seconds from now that token will expire. If not specified,
32: * an "exp" claim will not be added or updated
33: *
34: * @return string a token string returned from JsonWebToken::create()
35: *
36: * @throws \DomainException;
37: * @throws \InvalidArgumentException;
38: * @throws \UnexpectedValueException;
39: */
40: public static function build($keyName, $payload, $expirationOffset = 0)
41: {
42: $token = new JsonWebToken(KeyFactory::build($keyName));
43: return $token->create($payload, $expirationOffset);
44: }
45: }
46: