public function authorize(Application $app) {
        $server = $this->getAuthorizationServer($app);
        /** @var PasswordGrant $grant */
        $grant = $server->getGrantType('password');
        try {
            $result = $grant->completeFlow();
            return new JsonResponse($result);
        } catch (OAuthException $e) {
            return new JsonResponse(
                [
                    'error'     =>  $e->errorType,
                    'message'   =>  $e->getMessage(),
                ],
                $e->httpStatusCode ?: 500,
                $e->getHttpHeaders()
            );
        }
    }