From ac28498d8b96733dfa679ec86371aaa6825d3079 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 12 May 2015 18:35:07 +0200 Subject: Authentication with tokens --- .../BotleaguesApi/TokenAuthenticationProvider.php | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/CamilStaps/BotleaguesApi/TokenAuthenticationProvider.php (limited to 'src/CamilStaps/BotleaguesApi/TokenAuthenticationProvider.php') diff --git a/src/CamilStaps/BotleaguesApi/TokenAuthenticationProvider.php b/src/CamilStaps/BotleaguesApi/TokenAuthenticationProvider.php new file mode 100644 index 0000000..f3dad6e --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/TokenAuthenticationProvider.php @@ -0,0 +1,50 @@ +has(['user_id', 'token'])) { + throw new UnauthorizedHttpException(null, "Include user_id and token in your request."); + } + + $user = User::find($request->get('user_id')); + if ($user != null && $user->validToken($request->get('token'))) { + Auth::login($user); + return Auth::user(); + } + + throw new UnauthorizedHttpException(null, "Invalid credentials"); + } + + /** + * Get the providers authorization method. + * + * @return string + */ + public function getAuthorizationMethod() + { + return 'token'; + } +} \ No newline at end of file -- cgit v1.2.3