HTTPステータスコード401と403の違い
from 認証
HTTPステータスコード401と403
RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1
401 Unauthorized
意味はUnauthentication
Unauthorizedという名前が紛らわしい
The request requires user authentication. The response MUST include a
WWW-Authenticate header field (section 14.47) containing a challenge
applicable to the requested resource.
WWW-Authenticate 応答ヘッダーは、リソースへのアクセス権を得るために使われる認証方法を定義します。
WWW-Authenticate - HTTP | MDN
認証方法の一覧
Hypertext Transfer Protocol (HTTP) Authentication Scheme Registry
OAuth(RFC5849)も含まれる
403 Forbidden
RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1
The server understood the request, but is refusing to fulfill it.
Authorization will not help and the request SHOULD NOT be repeated.
HEAD以外のリクエストだったとき、リクエストが通らない理由をクライアントに説明したいなら、拒否った理由をentityに書く
If the request method was not HEAD and the server wishes to make
public why the request has not been fulfilled, it SHOULD describe the
reason for the refusal in the entity.
authorizationできなかった情報を出したくないなら404を返せばよい
If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead.
意味はUnauthorization
認証はできている(?)がリソースにアクセスする認可がない(Unauthorization)状態
403 Forbidden vs 401 Unauthorized HTTP responses - Stack Overflow