Skip to content

Commit

Permalink
Remove documentation/example of HTTP Digest Authorization
Browse files Browse the repository at this point in the history
It was declared obsolete as a standard in 2011. Some of the supporting
code is still technically part of the SAPI layer, but there's no reason
to document it here.

php/doc-en@61d5b83
  • Loading branch information
mumumu committed Jul 28, 2024
1 parent d1c626e commit 29f8203
Showing 1 changed file with 2 additions and 70 deletions.
72 changes: 2 additions & 70 deletions features/http-auth.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 2d1981cc3003cd94f5fb88e0473eed2c5b26efde Maintainer: hirokawa Status: ready -->
<!-- EN-Revision: 61d5b83d9145d58515ad4c93c6125a339fb5eeda Maintainer: hirokawa Status: ready -->
<!-- CREDITS: shimooka,takagi,mumumu -->
<chapter xml:id="features.http-auth" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>PHP による HTTP 認証</title>
Expand All @@ -18,8 +18,7 @@
パスワード、認証型が代入された状態で呼ばれます。
定義済みの変数は、配列
<varname>$_SERVER</varname> でアクセス可能です。
"Basic" 認証 と "Digest" 認証
<emphasis>のみ</emphasis> がサポートされています。詳細は、
"Basic" 認証 <emphasis>のみ</emphasis> がサポートされています。詳細は、
<function>header</function>を参照ください。
</simpara>

Expand All @@ -45,73 +44,6 @@ if (!isset($_SERVER['PHP_AUTH_USER'])) {
</example>
</para>

<para>
<example>
<title>Digest HTTP 認証の例</title>
<para>
この例は、シンプルな Digest HTTP 認証スクリプトをどの様に実装するか
を示しています。
その他情報については、<link xlink:href="&url.rfc;2617">RFC 2617</link>
を読んでください。
</para>
<programlisting role="php">
<![CDATA[
<?php
$realm = 'Restricted area';
//user => password
$users = array('admin' => 'mypass', 'guest' => 'guest');
if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Digest realm="'.$realm.
'",qop="auth",nonce="'.uniqid().'",opaque="'.md5($realm).'"');
die('ユーザーがキャンセルボタンを押した時に送信されるテキスト');
}
// PHP_AUTH_DIGEST 変数を精査する
if (!($data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) ||
!isset($users[$data['username']]))
die('誤った証明書です!');
// 有効なレスポンスを生成する
$A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]);
$A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']);
$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
if ($data['response'] != $valid_response)
die('誤った証明書です!');
// OK, 有効なユーザー名とパスワードだ
echo 'あなたは次のユーザーとしてログインしています: ' . $data['username'];
// http auth ヘッダをパースする関数
function http_digest_parse($txt)
{
// データが失われている場合への対応
$needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
$data = array();
$keys = implode('|', array_keys($needed_parts));
preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
foreach ($matches as $m) {
$data[$m[1]] = $m[3] ? $m[3] : $m[4];
unset($needed_parts[$m[1]]);
}
return $needed_parts ? false : $data;
}
?>
]]>
</programlisting>
</example>
</para>

<note>
<title>互換性に関する注意</title>
<para>
Expand Down

0 comments on commit 29f8203

Please sign in to comment.