SHARE
TWEET

Untitled

a guest Sep 21st, 2019 94 in 10 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php // file: app/Http/Controllers/API/V1/User/Auth/AccessTokenController.php
  2.  
  3. namespace App\Http\Controllers\API\V1\User\Auth;
  4.  
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\Controller;
  7. use App\Traits\RespondWithTokenTrait;
  8.  
  9. class AccessTokenController extends Controller
  10. {
  11.     use RespondWithTokenTrait;
  12.  
  13.     /**
  14.      * Get a JWT via given credentials.
  15.      *
  16.      * @return \Illuminate\Http\JsonResponse
  17.      */
  18.     public function issueToken()
  19.     {
  20.         $credentials = request(['email', 'password']);
  21.  
  22.         if (! $token = auth()->attempt($credentials)) {
  23.             return response()->json(['error' => 'Unauthorized'], 401);
  24.         }
  25.  
  26.         return $this->respondWithToken($token);
  27.     }
  28.  
  29.     /**
  30.      * Log the user out (Invalidate the token).
  31.      *
  32.      * @return \Illuminate\Http\JsonResponse
  33.      */
  34.     public function revokeToken()
  35.     {
  36.         auth()->logout();
  37.  
  38.         return response()->json(['message' => 'Successfully logged out']);
  39.     }
  40.  
  41.     public function refreshToken()
  42.     {
  43.         return $this->respondWithToken(auth()->refresh());
  44.     }
  45. }
  46. ?>
  47.  
  48. <?php // file: app/Http/Controllers/API/V1/Admin/Auth/AccessTokenController.php
  49.  
  50. namespace App\Http\Controllers\API\V1\Admin\Auth;
  51.  
  52. use Illuminate\Http\Request;
  53. use App\Http\Controllers\Controller;
  54. use App\Traits\RespondWithTokenTrait;
  55.  
  56. class AccessTokenController extends Controller
  57. {
  58.     use RespondWithTokenTrait;
  59.  
  60.     /**
  61.      * Get a JWT via given credentials.
  62.      *
  63.      * @return \Illuminate\Http\JsonResponse
  64.      */
  65.     public function issueToken()
  66.     {
  67.         $credentials = request(['email', 'password']);
  68.  
  69.         if (! $token = auth('admin_api')->attempt($credentials)) {
  70.             return response()->json(['error' => 'Unauthorized'], 401);
  71.         }
  72.  
  73.         return $this->respondWithToken($token);
  74.     }
  75.  
  76.     /**
  77.      * Log the user out (Invalidate the token).
  78.      *
  79.      * @return \Illuminate\Http\JsonResponse
  80.      */
  81.     public function revokeToken()
  82.     {
  83.         auth('admin_api')->logout();
  84.  
  85.         return response()->json(['message' => 'Successfully logged out']);
  86.     }
  87.  
  88.     public function refreshToken()
  89.     {
  90.         return $this->respondWithToken(auth('admin_api')->refresh());
  91.     }
  92. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top