[[NSDeveloper alloc] initWithName:@"Just another developer"]
Simple OpenID의 Delegate OpenID 버그 수정하기
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 뭔가 엉키거나 인덴테이션이 조금씩 엉키네. 컴퓨터는 역시 어려워 -_-;;
| Print article | This entry was posted by fribirdz on 2008/02/19 at 1:23 pm, and is filed under IT. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

about 4 years ago
안녕하세요.‘하루의 시작, RSS리더 피쉬’ 운영자 3fisher입니다.
RSS 구독을 통해 프리버즈 님이 작성해 주신 좋은 정보 잘 보고 있습니다. 늘 감사하게 생각합니다. ^^
프리버즈 님의 블로그 ‘Accelerated Fribirdz!’가 피쉬의 ‘추천채널 (http://www.3fishes.co.kr/fishstory)’ 에 소개되고 있다는 사실을 알려드리기 위해 이렇게 연락드립니다.
피쉬의 ‘추천채널’ 은 좋은 정보가 있는 사이트나 블로그를 3fisher가 선정해서 피쉬, 그리고 피쉬와의 제휴로 RSS리더가 서비스되는 다른 곳에도 함께 소개됩니다.
- 예: ‘한국아이닷컴 (http://blog.hankooki.com)’, ‘삼성SMS (http://www.yepp.co.kr/sms/main.jsp)’
소개에 앞서 미리 동의를 구하지 못한 점 양해 부탁 드리며, 혹 원치 않으실 수도 있다는 염려에 늦었지만 프리버즈 님의 의견을 여쭤봅니다.
더 많은 분들께서 프리버즈 님의 블로그를 통해 좋은 정보를 나누었으면 하는 바람이니 긍정적인 검토 부탁 드리고요.
만약 블로그 소개를 원하지 않으실 경우 이 글에 덧글로 의사를 알려주시면 저희가 방문해서 확인 후 ‘추천채널’에서 삭제하도록 하겠습니다.
더 자세한 내용이 궁금하시면 webmaster@3fishes.co.kr로 메일을 주시면 상세히 답변해 드리겠습니다.
감사합니다.
about 4 years ago
이 아이디와 내용과 분위기를 봐선 역시나 내가 알던 그 ‘분’?