百度OAuth2.0在接受驗證授權請求時,授權服務器會按照OAuth2.0協議對本次請求參數、請求頭部進行檢驗,若請求不合法或驗證未通過,授權服務器會返回相應的錯誤信息。
錯誤碼返回信息簡介
錯誤碼返回方式分兩種:
1、在瀏覽器訪問請求授權Endpoint”https://openapi.baidu.com/oauth/2.0/authorize”時返回,直接在瀏覽器頁面上顯示錯誤信息。
2、在應用的服務端訪問數據接口,如: 請求Access Token Endpoint”https://openapi.baidu.com/oauth/2.0/token”時返回,返回方式是返回一段JSON文本,包含以下字段:
error:錯誤碼;
error_description:錯誤描述信息,用來幫助理解和解決發生的錯誤。
例如:
HTTP/1.1 400 Bad Request
Content-Type: application/json
Cache-Control: no-store
{
“error”: “invalid_grant”,
“error_description”: “Invalid authorization code: ANXxSNjwQDugOnqeikRMu2bKaXCdlLxn”
invalid_request
invalid refresh token
請求缺少某個必需參數,包含一個不支持的參數或參數值,或者格式不正確。
invalid_client
unknown client id
client_id”、“client_secret”參數無效。
invalid_grant
The provided authorization grant is revoked
提供的Access Grant是無效的、過期的或已撤銷的,例如,Authorization Code無效(一個授權碼只能使用一次)、Refresh Token無效、redirect_uri與獲取Authorization Code時提供的不一致、Devie Code無效(一個設備授權碼只能使用一次)等。
unauthorized_client
The client is not authorized to use this authorization grant type
應用沒有被授權,無法使用所指定的grant_type。
unsupported_grant_type
The authorization grant type is not supported
“grant_type”百度OAuth2.0服務不支持該參數。
invalid_scope
The requested scope is exceeds the scope granted by the resource owner
請求的“scope”參數是無效的、未知的、格式不正確的、或所請求的權限范圍超過了數據擁有者所授予的權限范圍。
expired_token
refresh token has been used
提供的Refresh Token已過期
redirect_uri_mismatch
Invalid redirect uri
“redirect_uri”所在的根域與開發者注冊應用時所填寫的根域名不匹配。
unsupported_response_type
The response type is not supported
“response_type”參數值不為百度OAuth2.0服務所支持,或者應用已經主動禁用了對應的授權模式
slow_down
The device is polling too frequently
Device Flow中,設備通過Device Code換取Access Token的接口過于頻繁,兩次嘗試的間隔應大于5秒。
authorization_pending
User has not yet completed the authorization
Device Flow中,用戶還沒有對Device Code完成授權操作。
authorization_declined
User has declined the authorization
Device Flow中,用戶拒絕了對Device Code的授權操作。
invalid_referer
Invalid Referer
Implicit Grant模式中,瀏覽器請求的Referer與根域名綁定不匹配