Skip to content

Instantly share code, notes, and snippets.

@mirzap
Forked from basteln3rk/codiad_http_auth.php
Last active August 29, 2015 14:24
Show Gist options
  • Save mirzap/39fd77ff5426b43f1d09 to your computer and use it in GitHub Desktop.
Save mirzap/39fd77ff5426b43f1d09 to your computer and use it in GitHub Desktop.

How to do HTTP Authentication with Codiad

Codiad is a very powerful, user-friendly open source web-based IDE. Starting with version 2.x, there is a simple way to integrate external authentication with codiad. This gist shows to make Codiad use HTTP authentication, automatically adding a new user Codiad configuration if - whoever was authenticated by the HTTP server - does not have a Codiad account.

How to integrate it

In the Codiad folder, open the config.php file and look for the line that starts with define("AUTH_PATH",. Uncomment and set the second parameter of the define to codiad_http_auth.php.

Then save the codiad_http_auth.php file from below in the same folder and enjoy

Credit

I learned a lot from the Codiad-LDAPExternalAuth example

<?php
if (!isset($_SESSION['user'])) {
require_once( COMPONENTS . "/user/class.user.php" );
$_SESSION['user'] = $_SERVER['PHP_AUTH_USER'];
$_SESSION['lang'] = 'en';
$_SESSION['theme'] = 'default';
$_SESSION['project'] = '/var/www';
$User = new User();
$User->username = $_SERVER['PHP_AUTH_USER'];
if ($User->CheckDuplicate()) {
// confusingly, this means the user must be created
$User->users[] = array( 'username' => $User->username, 'password' => null, 'project' => "" );
saveJSON( "users.php", $User->users );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment