我正在關(guān)注雅虎官方文檔 (https://developer.yahoo.com/oauth2/guide/openid_connect/getting_started.html )。用戶使用雅虎登錄后,我可以成功獲取授權(quán)碼。我現(xiàn)在處于第 3 步,嘗試用授權(quán)代碼交換令牌,但 Yahoo 一直返回 http 錯(cuò)誤 500。為了從 Yahoo 交換訪問令牌的授權(quán)代碼,我使用以下 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 返回以下內(nèi)容: 內(nèi)容:{“錯(cuò)誤”:“ACCESS_TOKEN_GENERATION_FAILED”,“error_description”:“訪問令牌生成失敗”} 狀態(tài)代碼:InternalServerError官方文檔指出:“以下請(qǐng)求參數(shù)在請(qǐng)求體中使用HTTP POST傳輸。但是,您也可以在 HTTP 標(biāo)頭中發(fā)送參數(shù) client_id 和 client_secret”。我已經(jīng)嘗試了這兩種方法(clientid 和機(jī)密作為正文的一部分和基本授權(quán)標(biāo)頭),并且都返回相同的結(jié)果。當(dāng)發(fā)送 clientid 和機(jī)密作為基本授權(quán)標(biāo)頭的一部分時(shí),上面的兩個(gè)參數(shù)都將替換為以下內(nèi)容:client.Authenticator = new RestSharp.Authenticators.HttpBasicAuthenticator(codeModel.clientId, provider.Secret);如前所述,雅虎返回的唯一消息是“內(nèi)部服務(wù)器錯(cuò)誤”。RestSharp 語法是否有問題可能導(dǎo)致此問題?任何其他想法將不勝感激。不用說,請(qǐng)求的所有參數(shù)都包含了它們需要的數(shù)據(jù)。
1 回答

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