我正在開發支持多種身份驗證方案(OAuth
,Bearer
和Basic
)的REST API。當Authorization
不存在頭部或包含未支持的模式,服務與多個WWW-Authenticate
頭回應:多個身份驗證方案和WWW身份驗證挑戰
WWW-Authenticate: OAuth realm="myRealm"
WWW-Authenticate: Bearer realm="myRealm"
WWW-Authenticate: Basic realm="myRealm"
當請求包含一個Authorization
頭與支持的方案,但無效的憑證之一,應我的服務與迴應全部支持WWW-Authenticate
方案,或只是該方案提供的請求?
例如,如果一個客戶端提供:
Authorization: Bearer invalid
如果我的服務只用Bearer
應對挑戰?
WWW-Authenticate: Bearer realm="myRealm", error="invalid_token", error_description="token is malformed or represents invalid credentials"
還是應該回應所有WWW-Authenticate
挑戰?
WWW-Authenticate: Bearer realm="myRealm", error="invalid_token", error_description="token is malformed or represents invalid credentials"
WWW-Authenticate: OAuth realm="myRealm"
WWW-Authenticate: Basic realm="myRealm"
編輯:RFC 7235似乎提供了一個建議,雖然它不具體。我已經相應地添加了一個answer。
問題反饋:爲什麼*不*全部發送? –
我沒有在規範中找到任何明確的指導,並且除了所嘗試的其他方案/領域之外,還會給調用者造成困惑。這就是說,我同意,這是不夠的理由_不這樣做。我已經添加了[answer](https://stackoverflow.com/questions/45307985/multiple-authentication-schemes-and-www-authenticate-challenges/45335224#answer-45335224)。 – shelley