Skip to content

Instantly share code, notes, and snippets.

@basteln3rk
Created April 10, 2015 23:07
Show Gist options
  • Save basteln3rk/4cab14ebd990e46efaef to your computer and use it in GitHub Desktop.
Save basteln3rk/4cab14ebd990e46efaef to your computer and use it in GitHub Desktop.
HTTP Authentication for Codiad

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 );
}
}
@seanvree
Copy link

seanvree commented Aug 9, 2017

aren't you missing a " ?> " on line 18 @basteln3rk ?

@causefx
Copy link

causefx commented Aug 9, 2017

you don't have to close php files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment