@ -79,13 +79,10 @@ $app->get('/', function($format='html') use($app) {
$res = $app -> response ();
ob_start ();
render ( 'index' , array (
'title' => 'Teacup' ,
'meta' => ''
));
$html = ob_get_clean ();
$res -> body ( $html );
});
$app -> get ( '/auth/start' , function () use ( $app ) {
@ -97,12 +94,11 @@ $app->get('/auth/start', function() use($app) {
// aaronparecki.com http://aaronparecki.com http://aaronparecki.com/
// Normlize the value now (move this into a function in IndieAuth\Client later)
if ( ! array_key_exists ( 'me' , $params ) || ! ( $me = normalizeMeURL ( $params [ 'me' ]))) {
$html = render ( 'auth_error' , array (
render ( 'auth_error' , array (
'title' => 'Sign In' ,
'error' => 'Invalid "me" Parameter' ,
'errorDescription' => 'The URL you entered, "<strong>' . $params [ 'me' ] . '</strong>" is not valid.'
));
$app -> response () -> body ( $html );
return ;
}
@ -161,7 +157,7 @@ $app->get('/auth/start', function() use($app) {
$user -> type = $micropubEndpoint ? 'micropub' : 'local' ;
$user -> save ();
$html = render ( 'auth_start' , array (
render ( 'auth_start' , array (
'title' => 'Sign In' ,
'me' => $me ,
'authorizing' => $me ,
@ -172,7 +168,6 @@ $app->get('/auth/start', function() use($app) {
'authorizationEndpoint' => $authorizationEndpoint ,
'authorizationURL' => $authorizationURL
));
$app -> response () -> body ( $html );
}
});
@ -183,12 +178,11 @@ $app->get('/auth/callback', function() use($app) {
// Double check there is a "me" parameter
// Should only fail for really hacked up requests
if ( ! array_key_exists ( 'me' , $params ) || ! ( $me = normalizeMeURL ( $params [ 'me' ]))) {
$html = render ( 'auth_error' , array (
render ( 'auth_error' , array (
'title' => 'Auth Callback' ,
'error' => 'Invalid "me" Parameter' ,
'errorDescription' => 'The ID you entered, <strong>' . $params [ 'me' ] . '</strong> is not valid.'
));
$app -> response () -> body ( $html );
return ;
}
@ -199,34 +193,31 @@ $app->get('/auth/callback', function() use($app) {
}
if ( ! array_key_exists ( 'code' , $params ) || trim ( $params [ 'code' ]) == '' ) {
$html = render ( 'auth_error' , array (
render ( 'auth_error' , array (
'title' => 'Auth Callback' ,
'error' => 'Missing authorization code' ,
'errorDescription' => 'No authorization code was provided in the request.'
));
$app -> response () -> body ( $html );
return ;
}
// Verify the state came back and matches what we set in the session
// Should only fail for malicious attempts, ok to show a not as nice error message
if ( ! array_key_exists ( 'state' , $params )) {
$html = render ( 'auth_error' , array (
render ( 'auth_error' , array (
'title' => 'Auth Callback' ,
'error' => 'Missing state parameter' ,
'errorDescription' => 'No state parameter was provided in the request. This shouldn\'t happen. It is possible this is a malicious authorization attempt.'
));
$app -> response () -> body ( $html );
return ;
}
if ( $params [ 'state' ] != $_SESSION [ 'auth_state' ]) {
$html = render ( 'auth_error' , array (
render ( 'auth_error' , array (
'title' => 'Auth Callback' ,
'error' => 'Invalid state' ,
'errorDescription' => 'The state parameter provided did not match the state provided at the start of authorization. This is most likely caused by a malicious authorization attempt.'
));
$app -> response () -> body ( $html );
return ;
}
@ -275,12 +266,11 @@ $app->get('/auth/callback', function() use($app) {
// Verify the login actually succeeded
if ( ! k ( $token [ 'auth' ], 'me' )) {
$html = render ( 'auth_error' , array (
render ( 'auth_error' , array (
'title' => 'Sign-In Failed' ,
'error' => 'Unable to verify the sign-in attempt' ,
'errorDescription' => ''
));
$app -> response () -> body ( $html );
return ;
}
@ -317,7 +307,7 @@ $app->get('/auth/callback', function() use($app) {
if ( $skipDebugScreen ) {
$app -> redirect ( $_SESSION [ 'redirect_after_login' ], 301 );
} else {
$html = render ( 'auth_callback' , array (
render ( 'auth_callback' , array (
'title' => 'Sign In' ,
'me' => $me ,
'authorizing' => $me ,
@ -328,7 +318,6 @@ $app->get('/auth/callback', function() use($app) {
'curl_error' => ( array_key_exists ( 'error' , $token ) ? $token [ 'error' ] : false ),
'redirect' => $_SESSION [ 'redirect_after_login' ]
));
$app -> response () -> body ( $html );
}
});