Example #1
0
File: auth.php Project: jeena/Quill
 // 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('title' => 'Sign In', 'error' => 'Invalid "me" Parameter', 'errorDescription' => 'The URL you entered, "<strong>' . $params['me'] . '</strong>" is not valid.'));
     $app->response()->body($html);
     return;
 }
 if (k($params, 'redirect')) {
     $_SESSION['redirect_after_login'] = $params['redirect'];
 }
 $authorizationEndpoint = IndieAuth\Client::discoverAuthorizationEndpoint($me);
 $tokenEndpoint = IndieAuth\Client::discoverTokenEndpoint($me);
 $micropubEndpoint = IndieAuth\Client::discoverMicropubEndpoint($me);
 if ($tokenEndpoint && $micropubEndpoint && $authorizationEndpoint) {
     // Generate a "state" parameter for the request
     $state = IndieAuth\Client::generateStateParameter();
     $_SESSION['auth_state'] = $state;
     $scope = 'post';
     $authorizationURL = IndieAuth\Client::buildAuthorizationURL($authorizationEndpoint, $me, buildRedirectURI(), clientID(), $state, $scope);
 } else {
     $authorizationURL = false;
 }
 // If the user has already signed in before and has a micropub access token,
 // and the endpoints are all the same, skip the debugging screens and redirect
 // immediately to the auth endpoint.
 // This will still generate a new access token when they finish logging in.
 $user = ORM::for_table('users')->where('url', $me)->find_one();
 if ($user && $user->micropub_access_token && $user->micropub_endpoint == $micropubEndpoint && $user->token_endpoint == $tokenEndpoint && $user->authorization_endpoint == $authorizationEndpoint && !array_key_exists('restart', $params)) {
     // TODO: fix this by caching the endpoints maybe in the session instead of writing them to the DB here.
     // Then remove the line below that blanks out the access token
     $user->micropub_endpoint = $micropubEndpoint;