Lots of route and controller method names refactoring, which also necessitated editing of fetch methods in the front end es6 code
This commit is contained in:
parent
8a6e99d97e
commit
b8c0724036
23 changed files with 88 additions and 99 deletions
|
@ -4,7 +4,6 @@ namespace App\Http\Controllers;
|
|||
|
||||
use IndieAuth\Client;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use App\Services\TokenService;
|
||||
use Illuminate\Cookie\CookieJar;
|
||||
use App\Services\IndieAuthService;
|
||||
|
@ -52,7 +51,7 @@ class IndieAuthController extends Controller
|
|||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Routing\RedirectResponse redirect
|
||||
*/
|
||||
public function beginauth(Request $request)
|
||||
public function start(Request $request)
|
||||
{
|
||||
$authorizationEndpoint = $this->indieAuthService->getAuthorizationEndpoint(
|
||||
$request->input('me'),
|
||||
|
@ -69,7 +68,7 @@ class IndieAuthController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
return redirect('/notes/new')->withErrors('Unable to determine authorisation endpoint', 'indieauth');
|
||||
return redirect(route('micropub-client'))->withErrors('Unable to determine authorisation endpoint', 'indieauth');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,23 +78,24 @@ class IndieAuthController extends Controller
|
|||
* @param \Illuminate\Http\Rrequest $request
|
||||
* @return \Illuminate\Routing\RedirectResponse redirect
|
||||
*/
|
||||
public function indieauth(Request $request)
|
||||
public function callback(Request $request)
|
||||
{
|
||||
if ($request->session()->get('state') != $request->input('state')) {
|
||||
return redirect('/notes/new')->withErrors(
|
||||
return redirect(route('micropub-client'))->withErrors(
|
||||
'Invalid <code>state</code> value returned from indieauth server',
|
||||
'indieauth'
|
||||
);
|
||||
}
|
||||
$tokenEndpoint = $this->indieAuthService->getTokenEndpoint($request->input('me'), $this->client);
|
||||
$redirectURL = config('app.url') . '/indieauth';
|
||||
$clientId = config('app.url') . '/notes/new';
|
||||
if ($tokenEndpoint === false) {
|
||||
return redirect(route('micropub-client'))->withErrors('Unable to determine token endpoint', 'indieauth');
|
||||
}
|
||||
$data = [
|
||||
'endpoint' => $tokenEndpoint,
|
||||
'code' => $request->input('code'),
|
||||
'me' => $request->input('me'),
|
||||
'redirect_url' => $redirectURL,
|
||||
'client_id' => $clientId,
|
||||
'redirect_url' => route('indieauth-callback'),
|
||||
'client_id' => route('micropub-client'),
|
||||
'state' => $request->input('state'),
|
||||
];
|
||||
$token = $this->indieAuthService->getAccessToken($data, $this->client);
|
||||
|
@ -104,10 +104,22 @@ class IndieAuthController extends Controller
|
|||
$request->session()->put('me', $token['me']);
|
||||
$request->session()->put('token', $token['access_token']);
|
||||
|
||||
return redirect('/notes/new');
|
||||
return redirect(route('micropub-client'));
|
||||
}
|
||||
|
||||
return redirect('/notes/new')->withErrors('Unable to get a token from the endpoint', 'indieauth');
|
||||
return redirect(route('micropub-client'))->withErrors('Unable to get a token from the endpoint', 'indieauth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Log out the user, flush an session data, and overwrite any cookie data.
|
||||
*
|
||||
* @return \Illuminate\Routing\RedirectResponse redirect
|
||||
*/
|
||||
public function logout(Request $request)
|
||||
{
|
||||
$request->session()->flush();
|
||||
|
||||
return redirect(route('micropub-client'))->cookie('me', 'loggedout', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,25 +152,11 @@ class IndieAuthController extends Controller
|
|||
'access_token' => $token,
|
||||
]);
|
||||
|
||||
return (new Response($content, 200))
|
||||
->header('Content-Type', 'application/x-www-form-urlencoded');
|
||||
return response($content)
|
||||
->header('Content-Type', 'application/x-www-form-urlencoded');
|
||||
}
|
||||
$content = 'There was an error verifying the authorisation code.';
|
||||
|
||||
return new Response($content, 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log out the user, flush an session data, and overwrite any cookie data.
|
||||
*
|
||||
* @param \Illuminate\Cookie\CookieJar $cookie
|
||||
* @return \Illuminate\Routing\RedirectResponse redirect
|
||||
*/
|
||||
public function indieauthLogout(Request $request, CookieJar $cookie)
|
||||
{
|
||||
$request->session()->flush();
|
||||
$cookie->queue('me', 'loggedout', 5);
|
||||
|
||||
return redirect('/notes/new');
|
||||
return response($content, 400);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -193,7 +193,7 @@ class MicropubClientController extends Controller
|
|||
* @param \Illuminate\Http\Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function postNewPlace(Request $request)
|
||||
public function newPlace(Request $request)
|
||||
{
|
||||
if ($request->session()->has('token') === false) {
|
||||
return response()->json([
|
||||
|
@ -270,15 +270,10 @@ class MicropubClientController extends Controller
|
|||
* Make a request to the micropub endpoint requesting any nearby places.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $latitude
|
||||
* @param string $longitude
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function nearbyPlaces(
|
||||
Request $request,
|
||||
$latitude,
|
||||
$longitude
|
||||
) {
|
||||
public function nearbyPlaces(Request $request)
|
||||
{
|
||||
if ($request->session()->has('token') === false) {
|
||||
return response()->json([
|
||||
'error' => true,
|
||||
|
@ -298,7 +293,7 @@ class MicropubClientController extends Controller
|
|||
}
|
||||
|
||||
try {
|
||||
$query = 'geo:' . $latitude . ',' . $longitude;
|
||||
$query = 'geo:' . $request->input('latitude') . ',' . $request->input('longitude');
|
||||
if ($request->input('u') !== null) {
|
||||
$query .= ';u=' . $request->input('u');
|
||||
}
|
||||
|
@ -315,7 +310,7 @@ class MicropubClientController extends Controller
|
|||
], 400);
|
||||
}
|
||||
|
||||
return (new Response($response->getBody(), 200))
|
||||
return response($response->getBody(), 200)
|
||||
->header('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ class MicropubController extends Controller
|
|||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function getEndpoint(Request $request)
|
||||
public function get(Request $request)
|
||||
{
|
||||
$httpAuth = $request->header('Authorization');
|
||||
if (preg_match('/Bearer (.+)/', $httpAuth, $match)) {
|
||||
|
@ -162,16 +162,11 @@ class MicropubController extends Controller
|
|||
],
|
||||
]);
|
||||
}
|
||||
$content = 'No OAuth token sent with request.';
|
||||
$content = <<<'EOD'
|
||||
{
|
||||
"response": "error",
|
||||
"error": "no_token",
|
||||
"error_description": "No token provided with request"
|
||||
}
|
||||
EOD;
|
||||
|
||||
return (new Response($content, 400))
|
||||
->header('Content-Type', 'application/json');
|
||||
return response()->json([
|
||||
'response' => 'error',
|
||||
'error' => 'no_token',
|
||||
'error_description'
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ class IndieAuthService
|
|||
$domain = $client->normalizeMeURL($domain);
|
||||
$state = bin2hex(openssl_random_pseudo_bytes(16));
|
||||
session(['state' => $state]);
|
||||
$redirectURL = config('app.url') . '/indieauth';
|
||||
$clientId = config('app.url') . '/notes/new';
|
||||
$redirectURL = route('indieauth-callback');
|
||||
$clientId = route('micropub-client');
|
||||
$scope = 'post';
|
||||
$authorizationURL = $client->buildAuthorizationURL(
|
||||
$authEndpoint,
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1 +1 @@
|
|||
!function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var r={};return e.m=t,e.c=r,e.i=function(t){return t},e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=18)}({18:function(t,e){var r=/watch\?v=([A-Za-z0-9\-_]+)\b/,n=/https\:\/\/play\.spotify\.com\/(.*)\b/,o=document.querySelectorAll(".e-content"),a=!0,i=!1,u=void 0;try{for(var c,l=o[Symbol.iterator]();!(a=(c=l.next()).done);a=!0){var s=c.value,d=s.textContent.match(r);if(d){var f=document.createElement("div");f.classList.add("container");var p=document.createElement("iframe");p.classList.add("youtube"),p.setAttribute("src","https://www.youtube.com/embed/"+d[1]),p.setAttribute("frameborder",0),p.setAttribute("allowfullscreen","true"),f.appendChild(p),s.appendChild(f)}var m=s.textContent.match(n);if(m){var b=m[1].replace("/",":"),y=document.createElement("iframe");y.classList.add("spotify"),y.setAttribute("src","https://embed.spotify.com/?uri=spotify:"+b),y.setAttribute("frameborder",0),y.setAttribute("allowtransparency","true"),s.appendChild(y)}console.log(s.innerHTML)}}catch(t){i=!0,u=t}finally{try{!a&&l.return&&l.return()}finally{if(i)throw u}}}});
|
||||
!function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var r={};return e.m=t,e.c=r,e.i=function(t){return t},e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=18)}({18:function(t,e){var r=/watch\?v=([A-Za-z0-9\-_]+)\b/,n=/https\:\/\/play\.spotify\.com\/(.*)\b/,o=document.querySelectorAll(".e-content"),a=!0,u=!1,i=void 0;try{for(var c,l=o[Symbol.iterator]();!(a=(c=l.next()).done);a=!0){var s=c.value,d=s.textContent.match(r);if(d){var f=document.createElement("div");f.classList.add("container");var p=document.createElement("iframe");p.classList.add("youtube"),p.setAttribute("src","https://www.youtube.com/embed/"+d[1]),p.setAttribute("frameborder",0),p.setAttribute("allowfullscreen","true"),f.appendChild(p),s.appendChild(f)}var m=s.textContent.match(n);if(m){var b=m[1].replace("/",":"),y=document.createElement("iframe");y.classList.add("spotify"),y.setAttribute("src","https://embed.spotify.com/?uri=spotify:"+b),y.setAttribute("frameborder",0),y.setAttribute("allowtransparency","true"),s.appendChild(y)}}}catch(t){u=!0,i=t}finally{try{!a&&l.return&&l.return()}finally{if(u)throw i}}}});
|
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -46,7 +46,7 @@ const makeOptionsForForm = (map, position, places = null) => {
|
|||
|
||||
//position is output of navigator.geolocation call
|
||||
export default function addMapWithPlaces(div, position) {
|
||||
fetch('/places/near/' + position.coords.latitude + '/' + position.coords.longitude + '?u=' + position.coords.accuracy, {
|
||||
fetch('/micropub/places?latitude=' + position.coords.latitude + '&longitude=' + position.coords.longitude + '&u=' + position.coords.accuracy, {
|
||||
credentials: 'same-origin',
|
||||
method: 'get'
|
||||
}).then(function (response) {
|
||||
|
|
|
@ -82,7 +82,7 @@ export default function makeNewPlaceForm(map) {
|
|||
formData.append('place-latitude', document.querySelector('#place-latitude').value);
|
||||
formData.append('place-longitude', document.querySelector('#place-longitude').value);
|
||||
//post the new place
|
||||
fetch('/places/new', {
|
||||
fetch('/micropub/places', {
|
||||
//send cookies with the request
|
||||
credentials: 'same-origin',
|
||||
method: 'post',
|
||||
|
|
|
@ -13,7 +13,7 @@ New Note «
|
|||
<p class="error">{{ $errors->indieauth->first() }}</p>
|
||||
@endif
|
||||
@if($url === null)
|
||||
<form action="/beginauth" method="post" id="login">
|
||||
<form action="{{ route('indieauth-start') }}" method="post">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}">
|
||||
<fieldset>
|
||||
<legend>IndieAuth</legend>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
@if($syndication)
|
||||
<div>
|
||||
<label for="syndication" accesskey="s">Syndication: </label>
|
||||
<ul class="syndication-targets-list" name="syndication">
|
||||
<ul class="/micropub/syndication-targets-list" name="syndication">
|
||||
@foreach($syndication as $syn)
|
||||
<li><input type="checkbox"
|
||||
name="mp-syndicate-to[]"
|
||||
|
|
|
@ -98,18 +98,21 @@ Route::group(['domain' => config('url.longurl')], function () {
|
|||
Route::get('notes/tagged/{tag}', 'NotesController@tagged');
|
||||
|
||||
//indieauth
|
||||
Route::any('beginauth', 'IndieAuthController@beginauth');
|
||||
Route::get('indieauth', 'IndieAuthController@indieauth');
|
||||
Route::post('api/token', 'IndieAuthController@tokenEndpoint');
|
||||
Route::get('logout', 'IndieAuthController@indieauthLogout');
|
||||
Route::any('indieauth/start', 'IndieAuthController@start')->name('indieauth-start');
|
||||
Route::get('indieauth/callback', 'IndieAuthController@callback')->name('indieauth-callback');
|
||||
Route::get('logout', 'IndieAuthController@logout')->name('indieauth-logout');
|
||||
Route::post('api/token', 'IndieAuthController@tokenEndpoint'); //hmmm?
|
||||
|
||||
// Micropub
|
||||
// Micropub Client
|
||||
Route::get('micropub/create', 'MicropubClientController@create')->name('micropub-client');
|
||||
Route::post('micropub', 'MicropubClientController@store')->name('micropub-client-post');
|
||||
Route::get('api/post', 'MicropubController@getEndpoint');
|
||||
Route::get('micropub/refresh-syndication-targets', 'MicropubClientController@refreshSyndicationTargets');
|
||||
Route::get('micropub/places', 'MicropubClientController@nearbyPlaces');
|
||||
Route::post('micropub/places', 'MicropubClientController@newPlace');
|
||||
|
||||
// Micropub Endpoint
|
||||
Route::get('api/post', 'MicropubController@get');
|
||||
Route::post('api/post', 'MicropubController@post');
|
||||
//micropub refresh syndication targets
|
||||
Route::get('refresh-syndication-targets', 'MicropubClientController@refreshSyndicationTargets');
|
||||
|
||||
//webmention
|
||||
Route::get('webmention', function () {
|
||||
|
@ -124,9 +127,6 @@ Route::group(['domain' => config('url.longurl')], function () {
|
|||
//Places
|
||||
Route::get('places', 'PlacesController@index');
|
||||
Route::get('places/{slug}', 'PlacesController@show');
|
||||
//Places micropub
|
||||
Route::get('places/near/{lat}/{lng}', 'MicropubClientController@nearbyPlaces');
|
||||
Route::post('places/new', 'MicropubClientController@postNewPlace');
|
||||
|
||||
Route::get('feed', 'ArticlesController@makeRSS');
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue