From 488095c8f5141f822fa1b84669242c3f37d1cb4a Mon Sep 17 00:00:00 2001 From: milkmeowo Date: Wed, 9 Nov 2016 19:35:04 +0800 Subject: [PATCH 1/2] Passport Support For Dingo Api --- src/Someline/Api/Auth/Provider/Passport.php | 72 +++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/Someline/Api/Auth/Provider/Passport.php diff --git a/src/Someline/Api/Auth/Provider/Passport.php b/src/Someline/Api/Auth/Provider/Passport.php new file mode 100644 index 0000000..5ced6f3 --- /dev/null +++ b/src/Someline/Api/Auth/Provider/Passport.php @@ -0,0 +1,72 @@ +auth = $auth->guard($this->guard); + } + + /** + * Authenticate request with a Illuminate Guard. + * + * @param \Illuminate\Http\Request $request + * @param \Dingo\Api\Routing\Route $route + * + * @return mixed + */ + public function authenticate(Request $request, Route $route) + { + if (! $user = $this->auth->user()) { + throw new UnauthorizedHttpException( + get_class($this), + 'Unable to authenticate with invalid API key and token.' + ); + } + + return $user; + } + + /** + * Get the providers authorization method. + * + * @return string + */ + public function getAuthorizationMethod() + { + return 'Bearer'; + } +} + + From 11c9f6d7ff3090f9ef1657dbb81afeba77e5d04b Mon Sep 17 00:00:00 2001 From: milkmeowo Date: Thu, 10 Nov 2016 10:10:25 +0800 Subject: [PATCH 2/2] Improve --- src/Someline/Api/Auth/Provider/Passport.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Someline/Api/Auth/Provider/Passport.php b/src/Someline/Api/Auth/Provider/Passport.php index 5ced6f3..3211595 100644 --- a/src/Someline/Api/Auth/Provider/Passport.php +++ b/src/Someline/Api/Auth/Provider/Passport.php @@ -14,6 +14,7 @@ class Passport extends Authorization { + /** * Illuminate authentication manager. * @@ -48,11 +49,8 @@ public function __construct(AuthManager $auth) */ public function authenticate(Request $request, Route $route) { - if (! $user = $this->auth->user()) { - throw new UnauthorizedHttpException( - get_class($this), - 'Unable to authenticate with invalid API key and token.' - ); + if ( ! $user = $this->auth->user()) { + throw new UnauthorizedHttpException(null, 'Unauthenticated.'); } return $user;