commit fcebc08f6d89437ba84288a25498ae094fd4f16d Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Wed Jan 10 21:59:33 2018 +0000 update changelog commit 74491698857cb2e111006efb349e1f10c2e3cf1d Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Wed Jan 10 21:58:25 2018 +0000 Modify the micropub controller to look for the token in the right palce (as set by the token middleware commit 0fd11ff8391062fbe70f3a28d6a98694dc25b36b Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Wed Jan 10 21:57:40 2018 +0000 If the access token is sent as a bearer token in the http headers, merge it into the request data so the controllers only have one place to look commit 9e154ec4bc17be3071280409a3f6bb7f02dad816 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Wed Jan 10 21:56:33 2018 +0000 Add a test with the access token being form encoded
34 lines
777 B
PHP
34 lines
777 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
|
|
class VerifyMicropubToken
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure $next
|
|
* @return mixed
|
|
*/
|
|
public function handle($request, Closure $next)
|
|
{
|
|
if ($request->input('access_token')) {
|
|
return $next($request);
|
|
}
|
|
|
|
if ($request->bearerToken()) {
|
|
return $next($request->merge([
|
|
'access_token' => $request->bearerToken(),
|
|
]));
|
|
}
|
|
|
|
return response()->json([
|
|
'response' => 'error',
|
|
'error' => 'unauthorized',
|
|
'error_description' => 'No access token was provided in the request',
|
|
], 401);
|
|
}
|
|
}
|