PHP용 OpenID 라이브러리인 Simple OpenID는 파일 1개로만 이루어진 “인증전용” Consumer 라이브러리이다. Jan Rain의 라이브러리나 기타 다른 라이브러리보다 설정과 사용이 편리해, 많은 사람들이 사용하는 라이브러리 중 하나다.

나는 주로 Jan Rain의 라이브러리를 사용했었는데, 이번 OpenID 이벤트의 관리자 페이지에서는 Simple OpenID 를 사용했다. 그런데, 이 라이브러리에는 버그가 있었다. 글쎄, 어떻게 보면 버그가 아니라고 할 수도 있겠지만…

어쨋든, Simple OpenID를 사용하면, 간혹 델리게이션된 URL에서 OpenID를 찾지 못할 때가 있다. 즉, claimed ID에서 verified ID를 가져오지 못한다. 라이브러리를 디버깅해보니, “사소한[!]” 문제가 있었다.

아래는 class.openid.php의 HTML2OpenIDServer 함수이다.

[code]
function HTML2OpenIDServer($content) {
$get = array();

// Get details of their OpenID server and (optional) delegate
preg_match_all('/ ]*rel="openid.server"[^>]*href="([^"]+)"[^>]*\/?>/i', $content, $matches1);
preg_match_all('/ ]*href="([^"]+)"[^>]*rel="openid.server"[^>]*\/?>/i', $content, $matches2);

$servers = array_merge($matches1[1], $matches2[1]);

preg_match_all('/ ]*rel="openid.delegate"[^>]*href="([^"]+)"[^>]*\/?>/i', $content, $matches1);
preg_match_all('/ ]*href="([^"]+)"[^>]*rel="openid.delegate"[^>]*\/?>/i', $content, $matches2);

$delegates = array_merge($matches1[1], $matches2[1]);
$ret = array($servers, $delegates);
return $ret;
}
[/code]

뭔가 이상하지 않는가?

사용자가 제출한 OpenID URL에서 openid 정보를 가져오기 위해 위와 같은 정규표현식을 사용했는데, 여기에서는 rel=”openid.server”, href=” “, rel=”openid.delegate”, …와 같이 속성을 쌍따옴표(“)로 감쌌다고 가정하고 있다. 하지만, 사용자들이 모두 표준에 맞추어 쌍따옴표로 감싼다는 보장이 어디 있겠는가?

내 블로그(텍스트큐브)의 OpenID 플러그인에서도 다음과 같이 홑따옴표로 델리게이션 정보를 표기하고 있었다.

[code]
<link rel='openid.server' href='http://www.idtail.com/server'>   
<link rel='openid.delegate' href='http://fribirdz.idtail.com/'>  
[/code]

델리게이션을 사용하는 많은 사람들이 텍스트큐브를 사용할텐데, 에러를 종종 겪었을 거 같다. 요 부분은 텍스트큐브 측에 수정을 요청하였다. 티켓으로 올라갔으니, 1.6에서는 해결되리라 보인다.

그리고, 돌아가도록 정규표현식을 아래와 같이 (무식하게) 바꿨다.

[code]
function HTML2OpenIDServer($content) {
$get = array();

// Get details of their OpenID server and (optional) delegate
preg_match_all('/ ]*rel=["\']openid.server["\'][^>]*href=["\']([^"\']+)["\'][^>]*\/?>/i', $content, $matches1); preg_match_all('/ ]*href=["\']([^"\']+)["\'][^>]*rel=["\']openid.server["\'][^>]*\/?>/i', $content, $matches2);

$servers = array_merge($matches1[1], $matches2[1]);
preg_match_all('/ ]*rel=["\']openid.delegate["\'][^>]*href=["\']([^"\']+)["\'][^>]*\/?>/i', $content, $matches1); preg_match_all('/ ]*href=["\']([^"\']+)["\'][^>]*rel=["\']openid.delegate["\'][^>]*\/?>/i', $content, $matches2);

$delegates = array_merge($matches1[1], $matches2[1]);
$ret = array($servers, $delegates);
return $ret;
}
[/code]

결과는? 내 블로그에서도 델리게이션이 잘 된다.

혹시나 Simple OpenID를 사용하시는 분은, 위 함수를 바꿔주시면 잘 돌아갈 것이다.

Simple OpenID에서도 OpenID Spec. v2.0용 라이브러리를 발표했는데, 소스를 받아보니 다음과 같이 수정을 했더라. 근데, href는 여전히 쌍따옴표(“)로 감쌌다고 가정하고 있다. -.-;;

[code]

function HTML2OpenIDServer($content) {
$get = array();

// Get details of their OpenID server and (optional) delegate preg_match_all('/ ]*rel=["|\']openid.server["|\'][^>]*href="([^"]+)"[^>]*\/?>/i', $content, $matches1);
preg_match_all('/ ]*href="([^"]+)"[^>]*rel=["|\']openid.server["|\'][^>]*\/?>/i', $content, $matches2);

$servers = array_merge($matches1[1], $matches2[1]);

preg_match_all('/ ]*rel=["|\']openid.delegate["|\'][^>]*href="([^"]+)"[^>]*\/?>/i', $content, $matches1); preg_match_all('/ ]*href="([^"]+)"[^>]*rel=["|\']openid.delegate["|\'][^>]*\/?>/i', $content, $matches2);

$delegates = array_merge($matches1[1], $matches2[1]);

$ret = array($servers, $delegates);
return $ret;
} [/code]
PS : 소스코드 깔끔하게 나오게 하기 힘들다 T_T 뭔가 엉키거나 인덴테이션이 조금씩 엉키네. 컴퓨터는 역시 어려워 -_-;;