Jump to:

23371 Posts in 18161 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » BasicAuth::protect_entire_site() not working

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1565 Views
  • amdayton
    Avatar
    Community Member
    8 Posts

    BasicAuth::protect_entire_site() not working Link to this post

    Hello,

    I am setting up a staging site on a Dreamhost account, using the _ss_environment.php environment management setup described here. More specifically, in my _config.php I include the following line:

    if(Director::isTest()) BasicAuth::protect_entire_site();

    So I uploaded the site, setup the db + user accounts, etc. But then when I set it to "test," I get the login dialogue when visiting the site but none of the logins work. So essentially it is protecting the entire site, but none of the logins work! Any ideas?

    Thanks

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: BasicAuth::protect_entire_site() not working Link to this post

    Do the logins work normally? (in the cms).

    Try set a user for it using Security::setDefaultAdmin('user', 'pass'); and logging in with those details.

  • amdayton
    Avatar
    Community Member
    8 Posts

    Re: BasicAuth::protect_entire_site() not working Link to this post

    I have DefaultAdmin set in the _ss_environment.php file, and CMS logins are working fine. I tried defining DefaultAdmin in the _config.php file instead, still didn't work. Hmmm...

  • amdayton
    Avatar
    Community Member
    8 Posts

    Re: BasicAuth::protect_entire_site() not working Link to this post

    Argh, I gave up last time and ran into the same issue again, was hoping there might be a fix out there by now. All I found was my own forum post with no new answers. :/

  • pepe_legal
    Avatar
    Community Member
    1 Post

    Re: BasicAuth::protect_entire_site() not working Link to this post

    hi there!!

    I had the same problem as you described! When I had:

    Director::isDev()) BasicAuth::protect_entire_site();

    In windows it worked fine, but when i uploaded the code to a linux server...i couldn't pass the protection...so i searched a couple of things....and i found a solution for my problem.

    (http://www.besthostratings.com/articles/http-auth-php-cgi.html)

    in .htacess, inside <IfModule mod_rewrite.c>

    i added this: RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

    after i done a incursion inside the core (i didn't like that but for a major reason...), file: BasiAuth,php

    and in the function

    static function requireLogin($realm, $permissionCode = null, $tryUsingSessionLogin = true) {
    ...

    and after
       if(!Security::database_is_ready() || (Director::is_cli() && !$isRunningTests)) return true;
    i added:

    if(isset($_SERVER['HTTP_AUTHORIZATION'])&& !empty($_SERVER['HTTP_AUTHORIZATION'])){
             list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':' , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
          }

    And...this done the trick!

    Hope this help you and other people with the same problem!

    Regards!

  • Juanitou
    Avatar
    Community Member
    323 Posts

    Re: BasicAuth::protect_entire_site() not working Link to this post

    Thank you!

    I had the same problem and your post resolved it. Did you submitted this issue as a bug? I’m not an expert, but I think this could be considered as such.

    Best regards,
    Juan

    1565 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.