Browse Source

Merge pull request #53 from cweiske/dontask

Support full automatic no-questions-asked login
pull/64/head
Aaron Parecki 7 years ago
committed by GitHub
parent
commit
7d1a655fdc
1 changed files with 20 additions and 6 deletions
  1. +20
    -6
      controllers/auth.php

+ 20
- 6
controllers/auth.php View File

@ -1,12 +1,15 @@
<?php <?php
function buildRedirectURI() {
return Config::$base_url . 'auth/callback';
function buildRedirectURI($params = array()) {
return Config::$base_url . 'auth/callback?' . an class="nx">http_build_query($params);
} }
$app->get('/', function($format='html') use($app) { $app->get('/', function($format='html') use($app) {
$res = $app->response(); $res = $app->response();
$params = $app->request()->params();
if (k($params, 'me')) {
$app->redirect('/auth/start?'.http_build_query($params), 302);
}
ob_start(); ob_start();
render('index', array( render('index', array(
@ -49,7 +52,10 @@ $app->get('/auth/start', function() use($app) {
$_SESSION['auth_state'] = $state; $_SESSION['auth_state'] = $state;
$scope = 'post'; $scope = 'post';
$authorizationURL = IndieAuth\Client::buildAuthorizationURL($authorizationEndpoint, $me, buildRedirectURI(), Config::$base_url, $state, $scope);
$cleanparams = $params;
unset($cleanparams['me']);
unset($cleanparams['redirect']);
$authorizationURL = IndieAuth\Client::buildAuthorizationURL($authorizationEndpoint, $me, buildRedirectURI($cleanparams), Config::$base_url, $state, $scope);
} else { } else {
$authorizationURL = false; $authorizationURL = false;
} }
@ -86,6 +92,10 @@ $app->get('/auth/start', function() use($app) {
$user->micropub_access_token = ''; // blank out the access token if they attempt to sign in again $user->micropub_access_token = ''; // blank out the access token if they attempt to sign in again
$user->save(); $user->save();
if (k($params, 'dontask') && $params['dontask']) {
$app->redirect($authorizationURL, 302);
}
$html = render('auth_start', array( $html = render('auth_start', array(
'title' => 'Sign In', 'title' => 'Sign In',
'me' => $me, 'me' => $me,
@ -206,13 +216,17 @@ $app->get('/auth/callback', function() use($app) {
unset($_SESSION['auth_state']); unset($_SESSION['auth_state']);
if($redirectToDashboardImmediately) {
if($redirectToDashboardImmediately || k($params, 'dontask')) {
if(k($_SESSION, 'redirect_after_login')) { if(k($_SESSION, 'redirect_after_login')) {
$dest = $_SESSION['redirect_after_login']; $dest = $_SESSION['redirect_after_login'];
unset($_SESSION['redirect_after_login']); unset($_SESSION['redirect_after_login']);
$app->redirect($dest, 301); $app->redirect($dest, 301);
} else { } else {
$app->redirect('/new', 301);
$cleanparams = $params;
unset($cleanparams['code']);
unset($cleanparams['me']);
unset($cleanparams['state']);
$app->redirect('/new?' . http_build_query($cleanparams), 301);
} }
} else { } else {
$html = render('auth_callback', array( $html = render('auth_callback', array(

Loading…
Cancel
Save