src/Controller/Api/UsersController.php
public function token()
    {
        $user = $this->Auth->identify();
        if (!$user) {
            throw new UnauthorizedException('Invalid username or password');
        }

        $token = [
            'id' => $user['id'],
            'exp' => time() + 60 * 60 * 24 * 7
        ];

        $this->set([
            'success' => true,
            'data' => ['token' => JWT::encode($token, Security::salt())],
            '_serialize' => ['success', 'data']
        ]);
    }
public function token()
    {
        $user = $this->Auth->identify();
        if (!$user) {
            throw new UnauthorizedException('Invalid username or password');
        }

        $token = [
            'id' => $user['id'],
            'exp' => time() + 60 * 60 * 24 * 7
        ];

        $this->set([
            'success' => true,
            'data' => ['token' => JWT::encode($token, Security::salt())],
            '_serialize' => ['success', 'data']
        ]);
    }
public function token ( ) { $ user = $ this -> Auth -> identify ( ) ; if ( ! $ user ) { throw new UnauthorizedException ( 'Invalid username or password' ) ; } $ token = [ 'id' => $ user [ 'id' ] , 'exp' => time ( ) + 60 * 60 * 24 * 7 ] ; $ this -> set ( [ 'success' => true , 'data' => [ 'token' => JWT :: encode ( $ token , Security :: salt ( ) ) ] , '_serialize' => [ 'success' , 'data' ] ] ) ; }
Tries to authentify user based on POST data and returns a private token

@return void
Tries to authentify user based on POST data and returns a private token