Conditions | 4 |
Paths | 3 |
Total Lines | 23 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
19 | public function token() |
||
20 | { |
||
21 | $realm = $this->request->query('realm'); |
||
22 | $realms = Configure::read('WyriHaximus.Ratchet.realms'); |
||
23 | if (!isset($realms[$realm])) { |
||
24 | throw new \InvalidArgumentException('Unknown realm'); |
||
25 | } |
||
26 | if (!isset($realms[$realm]['auth_key'])) { |
||
27 | throw new \InvalidArgumentException('Unknown realm'); |
||
28 | } |
||
29 | |||
30 | $user = $this->Auth->user(); |
||
31 | $this->set( |
||
32 | 'token', |
||
33 | JWT::encode( |
||
34 | [ |
||
35 | 'authId' => $user === null ? 0 : get_in($user, ['id'], 0), |
||
36 | ], |
||
37 | $realms[$realm]['auth_key'] |
||
38 | ) |
||
39 | ); |
||
40 | $this->set('_serialize', ['token']); |
||
41 | } |
||
42 | } |
||
43 |