-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working dingo+jwt auth with example routes
- Loading branch information
Showing
9 changed files
with
1,017 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
APP_ENV=local | ||
APP_DEBUG=true | ||
APP_KEY=SomeRandomKey!!! | ||
|
||
APP_LOCALE=en | ||
APP_FALLBACK_LOCALE=en | ||
|
||
DB_CONNECTION=mysql | ||
DB_HOST=localhost | ||
DB_PORT=3306 | ||
DB_DATABASE=lumendingojwtapi | ||
DB_USERNAME=homestead | ||
DB_PASSWORD=secret | ||
|
||
CACHE_DRIVER=memcached | ||
SESSION_DRIVER=memcached | ||
QUEUE_DRIVER=database | ||
|
||
# MAIL_DRIVER=smtp | ||
# MAIL_HOST=mailtrap.io | ||
# MAIL_PORT=2525 | ||
# MAIL_USERNAME=null | ||
# MAIL_PASSWORD=null | ||
# MAIL_FROM_ADDRESS=null | ||
# MAIL_FROM_NAME=null | ||
|
||
# FILESYSTEM_DRIVER=local | ||
# FILESYSTEM_CLOUD=s3 | ||
|
||
# S3_KEY=null | ||
# S3_SECRET=null | ||
# S3_REGION=null | ||
# S3_BUCKET=null | ||
|
||
# RACKSPACE_USERNAME=null | ||
# RACKSPACE_KEY=null | ||
# RACKSPACE_CONTAINER=null | ||
# RACKSPACE_REGION=null | ||
|
||
# DINGO/API | ||
API_STANDARDS_TREE=vnd | ||
API_DOMAIN=lumendingojwtapi.local | ||
API_VERSION=v1 | ||
API_NAME=lumendingojwtapi | ||
API_CONDITIONAL_REQUEST=true | ||
API_STRICT=false | ||
API_DEBUG=true | ||
|
||
# JWT | ||
JWT_SECRET=GenerateWith:: #php artisan jwt:secret |
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,34 @@ | ||
<?php namespace App\Http\Controllers; | ||
|
||
use Dingo\Api\Http\Request; | ||
use Tymon\JWTAuth\JWTAuth; | ||
use Tymon\JWTAuth\Exceptions\JWTException; | ||
|
||
class AuthenticateController extends Controller | ||
{ | ||
protected $auth; | ||
|
||
public function __construct(JWTAuth $auth) | ||
{ | ||
$this->auth = $auth; | ||
} | ||
|
||
public function backend(Request $request) | ||
{ | ||
// grab credentials from the request | ||
$credentials = $request->only('email', 'password'); | ||
|
||
try { | ||
// attempt to verify the credentials and create a token for the user | ||
if (! $token = $this->auth->attempt($credentials)) { | ||
return response()->json(['error' => 'invalid_credentials'], 401); | ||
} | ||
} catch (JWTException $e) { | ||
// something went wrong whilst attempting to encode the token | ||
return response()->json(['error' => 'could_not_create_token'], 500); | ||
} | ||
|
||
// all good so return the token | ||
return response()->json(compact('token')); | ||
} | ||
} |
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,22 @@ | ||
<?php namespace App\Http\Controllers; | ||
|
||
use Dingo\Api\Http\Request; | ||
use Dingo\Api\Routing\Helpers; | ||
|
||
use Symfony; | ||
|
||
|
||
class BackendController extends Controller | ||
{ | ||
|
||
/** | ||
* @param Request $request | ||
* @return mixed | ||
*/ | ||
public function index (Request $request) | ||
{ | ||
$user = app('Dingo\Api\Auth\Auth')->user(); | ||
|
||
return $user; | ||
} | ||
} |
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.