-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config/main update readme; adding coday to ci workflow; using jwt for…
… auth; updating tests; readme for updates on auth not updated as its not final
- Loading branch information
Showing
16 changed files
with
890 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use App\Http\Controllers\Controller; | ||
|
||
class AuthController extends Controller | ||
{ | ||
/** | ||
* Create a new AuthController instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->middleware('auth:api', ['except' => ['login']]); | ||
} | ||
|
||
/** | ||
* Get a JWT via given credentials. | ||
* | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function login(Request $request) | ||
{ | ||
$credentials = [ | ||
'email' => $request->getUser(), | ||
'password' => $request->getPassword(), | ||
]; | ||
|
||
if (! $token = auth()->attempt($credentials)) { | ||
return response()->json(['error' => 'Unauthorized'], 401); | ||
} | ||
|
||
return $this->respondWithToken($token); | ||
} | ||
|
||
/** | ||
* Log the user out (Invalidate the token). | ||
* | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function logout() | ||
{ | ||
auth()->logout(); | ||
|
||
return response()->json(['message' => 'Successfully logged out']); | ||
} | ||
|
||
/** | ||
* Refresh a token. | ||
* | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function refresh() | ||
{ | ||
return $this->respondWithToken(auth()->refresh(true)); | ||
} | ||
|
||
/** | ||
* Get the token array structure. | ||
* | ||
* @param string $token | ||
* | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
protected function respondWithToken($token) | ||
{ | ||
return response()->json([ | ||
'access_token' => $token, | ||
'token_type' => 'bearer', | ||
'expires_in' => auth()->factory()->getTTL() * 60 | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.