{"action":"opened","issue":{"url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/1347","repository_url":"https://api.github.com/repos/tymondesigns/jwt-auth","labels_url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/1347/labels{/name}","comments_url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/1347/comments","events_url":"https://api.github.com/repos/tymondesigns/jwt-auth/issues/1347/events","html_url":"https://github.com/tymondesigns/jwt-auth/issues/1347","id":265574030,"number":1347,"title":"I visit /api/auth/logout why it tip me :Unauthenticated.","user":{"login":"zhangwei900808","id":4385154,"avatar_url":"https://avatars1.githubusercontent.com/u/4385154?v=4","gravatar_id":"","url":"https://api.github.com/users/zhangwei900808","html_url":"https://github.com/zhangwei900808","followers_url":"https://api.github.com/users/zhangwei900808/followers","following_url":"https://api.github.com/users/zhangwei900808/following{/other_user}","gists_url":"https://api.github.com/users/zhangwei900808/gists{/gist_id}","starred_url":"https://api.github.com/users/zhangwei900808/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhangwei900808/subscriptions","organizations_url":"https://api.github.com/users/zhangwei900808/orgs","repos_url":"https://api.github.com/users/zhangwei900808/repos","events_url":"https://api.github.com/users/zhangwei900808/events{/privacy}","received_events_url":"https://api.github.com/users/zhangwei900808/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-10-15T13:58:30Z","updated_at":"2017-10-15T13:58:30Z","closed_at":null,"author_association":"NONE","body":"AuthController.php\r\n```\r\n<?php\r\n\r\nnamespace Awbeci\\Http\\Controllers;\r\nuse Illuminate\\Support\\Facades\\Auth;\r\nuse Awbeci\\Http\\Models\\User;\r\nuse Awbeci\\Http\\Controllers\\Controller;\r\n\r\nuse Illuminate\\Http\\Request;\r\n\r\n\r\nclass AuthController extends Controller\r\n{\r\n    /**\r\n     * Create a new AuthController instance.\r\n     *\r\n     * @return void\r\n     */\r\n    public function __construct()\r\n    {\r\n        $this->middleware('auth:api', ['except' => ['login']]);\r\n    }\r\n\r\n    /**\r\n     * Get a JWT token via given credentials.\r\n     *\r\n     * @param  \\Illuminate\\Http\\Request  $request\r\n     *\r\n     * @return \\Illuminate\\Http\\JsonResponse\r\n     */\r\n    public function login(Request $request)\r\n    {\r\n        $this->validate($request, [\r\n            'email' => 'required|string|email|max:255',\r\n            'password' => 'required|string|min:6'\r\n        ]);\r\n        $email = $request->input('email');\r\n        $password = $request->input('password');\r\n\r\n        //验证用户\r\n        if (Auth::attempt([\r\n            'email' => $email,\r\n            'password' => $password\r\n        ], true)\r\n        ) {\r\n            //验证用户通过下面生成jwt token并返回\r\n            $credentials = $request->only('email', 'password');\r\n            if ($token = $this->guard()->attempt($credentials)) {\r\n                return response()->json([\r\n                    'success' => true,\r\n                    'msg' => 'Successfully login!',\r\n                    'access_token' => $token,\r\n                    'user' => Auth::user()\r\n                ], 201);\r\n            }\r\n        }\r\n        $email_count = User::where('email', '=', $email)->count();\r\n        return response()->json([\r\n            'success' => false,\r\n            'msg' => '邮箱或者密码有误，请重新输入！',\r\n            'emailCount' => $email_count\r\n        ]);\r\n    }\r\n\r\n    /**\r\n     * Get the authenticated User\r\n     *\r\n     * @return \\Illuminate\\Http\\JsonResponse\r\n     */\r\n    public function me()\r\n    {\r\n        return response()->json($this->guard()->user());\r\n    }\r\n\r\n    /**\r\n     * Log the user out (Invalidate the token)\r\n     *\r\n     * @return \\Illuminate\\Http\\JsonResponse\r\n     */\r\n    public function logout()\r\n    {\r\n        $this->guard()->logout();\r\n\r\n        return response()->json([\r\n            'success'=>true,\r\n            'message' => 'Successfully logged out'\r\n        ]);\r\n    }\r\n\r\n    /**\r\n     * Refresh a token.\r\n     *\r\n     * @return \\Illuminate\\Http\\JsonResponse\r\n     */\r\n    public function refresh()\r\n    {\r\n        return $this->respondWithToken($this->guard()->refresh());\r\n    }\r\n\r\n    /**\r\n     * Get the token array structure.\r\n     *\r\n     * @param  string $token\r\n     *\r\n     * @return \\Illuminate\\Http\\JsonResponse\r\n     */\r\n    protected function respondWithToken($token)\r\n    {\r\n        return response()->json([\r\n            'access_token' => $token,\r\n            'token_type' => 'bearer',\r\n            'expires_in' => $this->guard()->factory()->getTTL() * 60\r\n        ]);\r\n    }\r\n\r\n    /**\r\n     * Get the guard to be used during authentication.\r\n     *\r\n     * @return \\Illuminate\\Contracts\\Auth\\Guard\r\n     */\r\n    public function guard()\r\n    {\r\n        return Auth::guard();\r\n    }\r\n}\r\n\r\n```\r\n\r\napi.php\r\n```\r\nRoute::group([\r\n    'middleware' => 'api',\r\n    'prefix' => 'auth'\r\n], function ($router) {\r\n    Route::post('login', 'AuthController@login');\r\n    Route::post('logout', 'AuthController@logout');\r\n});\r\n```\r\n![image](https://user-images.githubusercontent.com/4385154/31585431-fb92ac8a-b186-11e7-8a16-8614b0f28128.png)\r\n"}}
{"actor":{"display_login":"zhangwei900808"}}