2013-12-16 2 views
4

Phil Sturgeon의 REST 서버를 사용하고 있습니다. 기본 인증 또는 다이제스트 인증을 설정하는 데 문제가 있습니다. 메서드를 호출 할 때 올바른 사용자 이름과 암호를 입력해도 사용자 이름과 암호를 묻는 대화 상자가 나타납니다. 이 문제를 어떻게 해결합니까? 그것을 허용하지 않는 웹 호스트입니까?Codeigniter 나머지 서버 다이제스트 또는 기본 인증 로그인

이것은 rest.php에 auth를 설정하는 방법입니다. 나머지는 기본값입니다.

$config['rest_auth']   = 'Basic'; 
$config['auth_source']  = ''; 
$config['rest_valid_logins'] = array('admin' => 'password'); 

답변

7

나는 해결책을 직접 만들었습니다. .htaccess 파일에이 파일을 추가해야했습니다. 로컬 호스트가하는 것처럼

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

나를 위해이 didnt 한 일을하지만 나를 위해

했다 그것은는 FastCGI를 아닌 php5_module로하여 단절 실행 PHP 관련.

전에/REST_Controller.php

여기

된 솔루션 http://ellislab.com/forums/viewthread/173823/#825912

htaccess로

RewriteEngine on 
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L] 

라이브러리 : - (CGI/FastCGI를 서버 API 실행은 phpinfo이를 찾을 수)

// most other servers 
elseif ($this->input->server('HTTP_AUTHENTICATION')) 
{ 
if (strpos(strtolower($this->input->server('HTTP_AUTHENTICATION')),'basic') === 0) 
{ 
    list($username,$password) = explode(':',base64_decode(substr($this->input- >server('HTTP_AUTHORIZATION'), 6))); 
} 
} 

후에

// most other servers 
elseif ($this->input->server('HTTP_AUTHENTICATION') || $this->input- >server('REDIRECT_REMOTE_USER')) 
{ 
$HTTP_SERVER_AUTH = ($this->input->server('HTTP_AUTHENTICATION')) ? $this->input->server('HTTP_AUTHENTICATION') : $this->input->server('REDIRECT_REMOTE_USER'); 

if (strpos(strtolower($HTTP_SERVER_AUTH),'basic') === 0) 
{ 
    list($username,$password) = explode(':',base64_decode(substr($HTTP_SERVER_AUTH, 6))); 
} 
} 
4

그런 오래된 스레드로 작성해 주셔서 죄송합니다. 누군가의 시간을 절약 할 수 있다고 생각했습니다.

이 솔루션은 기본 인증 용입니다. 나는 이것을 digest auth로 테스트하지 않았다.

.htaccess를 작동 시키려면 @ Tan의 대답을 약간 조정해야합니다.

내가 RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]에서 [L]를 제거하고 단지 RewriteEngine on

htaccess로 파일 후 재 작성 규칙을 배치 :

RewriteEngine On 
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 

#Other rules follow 

다음으로, 응용 프로그램/설정 내부 rest.php 설정 파일을 변경하는 데 필요한 예배 규칙서. 다음과 같이 내가 만든 변경 사항은 다음과 같습니다

<?php defined('BASEPATH') OR exit('No direct script access allowed'); 

class Api_auth 
{ 
    public function login($username, $password) { 
     if($username == 'admin' && $password == '1234') 
     { 
      return true;    
     } 
     else 
     { 
      return false;   
     }   
    } 
} 
:

$config['auth_source'] = 'ldap' $config['auth_library_class'] = '' $config['auth_library_function'] = '' 다음

$config['auth_library_function'] = 'login'-$config['auth_library_class'] = 'api_auth'에, $config['auth_source'] = 'library'에, 나는 다음과 같은 코드를 가진 Api_auth.php라는 새로운 라이브러리 파일을 생성

언젠가 누군가에게 도움이되기를 바랍니다.