我正在關注雅虎官方文檔 (https://developer.yahoo.com/oauth2/guide/openid_connect/getting_started.html )。用戶使用雅虎登錄后,我可以成功獲取授權碼。我現在處于第 3 步,嘗試用授權代碼交換令牌,但 Yahoo 一直返回 http 錯誤 500。為了從 Yahoo 交換訪問令牌的授權代碼,我使用以下 RestSharp 語法:var client = new RestClient(provider.TokenUrl);RestRequest request = new RestRequest() { Method = Method.POST };request.AddParameter("client_id", codeModel.clientId, ParameterType.GetOrPost);request.AddParameter("client_secret", provider.Secret, ParameterType.GetOrPost);request.AddParameter("code", codeModel.code, ParameterType.GetOrPost);request.AddParameter("grant_type", "authorization_code", ParameterType.GetOrPost);request.AddParameter("redirect_uri", codeModel.redirectUri, ParameterType.GetOrPost);request.AddHeader("Content-Type", "application/x-www-form-urlencoded");var response = client.Execute<TokenResponseModel>(request);responde.data 返回以下內容: 內容:{“錯誤”:“ACCESS_TOKEN_GENERATION_FAILED”,“error_description”:“訪問令牌生成失敗”} 狀態代碼:InternalServerError官方文檔指出:“以下請求參數在請求體中使用HTTP POST傳輸。但是,您也可以在 HTTP 標頭中發送參數 client_id 和 client_secret”。我已經嘗試了這兩種方法(clientid 和機密作為正文的一部分和基本授權標頭),并且都返回相同的結果。當發送 clientid 和機密作為基本授權標頭的一部分時,上面的兩個參數都將替換為以下內容:client.Authenticator = new RestSharp.Authenticators.HttpBasicAuthenticator(codeModel.clientId, provider.Secret);如前所述,雅虎返回的唯一消息是“內部服務器錯誤”。RestSharp 語法是否有問題可能導致此問題?任何其他想法將不勝感激。不用說,請求的所有參數都包含了它們需要的數據。
1 回答

撒科打諢
TA貢獻1934條經驗 獲得超2個贊
當您在 YDN 創建應用程序配置文件時,您必須確保至少選擇一項 API 權限。例如,嘗試“個人資料(社交目錄)公開讀取”。
如果您的應用程序沒有 API 權限,那么令牌生成將會按照您所描述的方式失敗。
如果您已經創建了沒有權限的應用程序,則必須將其刪除并重新創建。
- 1 回答
- 0 關注
- 193 瀏覽
添加回答
舉報
0/150
提交
取消