aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/http/headers/access-control-allow-credentials/index.html
blob: 133be568239b939870690f034cb159a8f65a2ed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
title: Access-Control-Allow-Credentials
slug: Web/HTTP/Headers/Access-Control-Allow-Credentials
tags:
  - Access-Control-Allow-Credentials
  - CORS
  - HTTP
  - Reference
  - credentials
  - header
  - レスポンスヘッダー
  - 資格情報
translation_of: Web/HTTP/Headers/Access-Control-Allow-Credentials
---
<div>{{HTTPSidebar}}</div>

<p><strong><code>Access-Control-Allow-Credentials</code></strong> レスポンスヘッダーは、リクエストの資格情報モード ({{domxref("Request.credentials")}}) が <code>include</code> である場合に、レスポンスをフロントエンドの JavaScript コードに公開するかどうかをブラウザーに指示します。</p>

<p>証明書の資格情報モード ({{domxref("Request.credentials")}}) が <code>include</code> である場合、レスポンスがフロントエンドの JavaScript コードに公開されるのは <code>Access-Control-Allow-Credentials</code> の値が <code>true</code> である場合のみです。</p>

<p>資格情報は Cookie、認証ヘッダー、または TLS クライアント証明書です。</p>

<p>プリフライトリクエストに対するレスポンスの一部として使用された場合は、実際のリクエストが資格情報を使用して行われた可能性があるかどうかを示します。なお、単純な {{HTTPMethod("GET")}} リクエストはプリフライトが行われないので、資格情報を持つリソースに対してリクエストが行われた場合、このヘッダーがリソースとともに返されない場合、レスポンスはブラウザーによって無視されウェブコンテンツは返されません。</p>

<p><code>Access-Control-Allow-Credentials</code> ヘッダーは、 {{domxref("XMLHttpRequest.withCredentials")}} プロパティまたは Fetch API の {{domxref("Request.Request()", "Request()")}} コンストラクター内の <code>credentials</code> オプションとの組み合わせで動作します。資格情報を含む CORS リクエストにおいて、ブラウザーがレスポンスを JavaScript コードに公開するようにするためには、サーバー側 (<code>Access-Control-Allow-Credentials</code> ヘッダーを使用) とクライアント側 (XHR, Fetch Ajax リクエストの資格情報モードの設定) の両方が、資格情報を含むことを承認しなければなりません。</p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">ヘッダー種別</th>
   <td>{{Glossary("Response header", "レスポンスヘッダー")}}</td>
  </tr>
  <tr>
   <th scope="row">{{Glossary("Forbidden header name", "禁止ヘッダー名")}}</th>
   <td>いいえ</td>
  </tr>
 </tbody>
</table>

<h2 id="Syntax" name="Syntax">構文</h2>

<pre class="syntaxbox">Access-Control-Allow-Credentials: true
</pre>

<h2 id="Directives" name="Directives">ディレクティブ</h2>

<dl>
 <dt>true</dt>
 <dd>このヘッダーの唯一の有効な値は <code>true</code> です (大文字小文字を区別します)。資格情報を必要としない場合は、 (値を false に設定するのではなく) このヘッダーを完全に省略します。</dd>
</dl>

<h2 id="Examples" name="Examples"></h2>

<p>資格情報の許可:</p>

<pre>Access-Control-Allow-Credentials: true</pre>

<p><a href="/ja/docs/Web/API/XMLHttpRequest">XHR</a> を資格情報付きで使用:</p>

<pre class="brush: js">var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://example.com/', true);
xhr.withCredentials = true;
xhr.send(null);</pre>

<p><a href="/ja/docs/Web/API/Fetch_API">Fetch</a> を資格情報付きで使用:</p>

<pre class="brush: js">fetch(url, {
  credentials: 'include'
})</pre>

<h2 id="Specifications" name="Specifications">仕様書</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">仕様書</th>
   <th scope="col">状態</th>
   <th scope="col">備考</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('Fetch','#http-access-control-allow-credentials', 'Access-Control-Allow-Credentials')}}</td>
   <td>{{Spec2("Fetch")}}</td>
   <td>初回定義</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>

<p>{{Compat("http.headers.Access-Control-Allow-Credentials")}}</p>

<h2 id="See_also" name="See_also">関連情報</h2>

<ul>
 <li>{{domxref("XMLHttpRequest.withCredentials")}}</li>
 <li>{{domxref("Request.Request()", "Request()")}}</li>
</ul>