[英]Spring boot security oauth2 get access_token from cookie
[英]Oauth2 Get access_token from UBER
我試圖將授權代碼轉換為訪問令牌,但得到“ BAD REQUEST”(400)和空響應正文。
這是我的代碼:
Scanner in = new Scanner(System.in);
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("https://login.uber.com/oauth/token");
post.setRequestHeader("Content-Type", URLEncoder.encode("application/x-www-form-urlencoded", "UTF-8"));
post.setParameter("grant_type",URLEncoder.encode("authorization_code", "UTF-8"));
post.setParameter("client_id",URLEncoder.encode("mq_LxaL0P-Kn8Wq3TmuhztFkOhISxReq", "UTF-8"));
post.setParameter("client_secret",URLEncoder.encode("MY_SECRET", "UTF-8"));
post.setParameter("redirect_uri",URLEncoder.encode("https://jfpmrvbais.localtunnel.me/TaxyNow/webresources/generic", "UTF-8"));
post.setParameter("code", URLEncoder.encode("S9UOTmXLGp20GF6y7TFf9pw5Pkekrl", "UTF-8"));
client.executeMethod(post);
String responseBody = post.getResponseBodyAsString();
String statusCode= post.getStatusText();
UBER相關文檔 。
我正在尋找解決方案兩天。 另外,我檢查了stackoverflow中所有類似的問題,但沒有發現任何問題。
非常感謝
編輯:問題已解決,以下是工作代碼:
HttpClient client = new HttpClient();
PostMethod post = new PostMethod("https://login.uber.com/oauth/token");
post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
post.setRequestHeader("Accept", "application/json");
post.setParameter("client_secret",MY_SECRET);
post.setParameter("client_id",clientId);
post.setParameter("grant_type", "authorization_code");
post.setParameter("redirect_uri", REDIRECT_URL);
post.setParameter("code", code);
重要的一件事:他們要求您插入在上一個請求中插入的相同redirect_url。
您是否嘗試過使用圖書館來處理OAuth? 該文檔說:“我們建議您使用預建的庫來執行授權和令牌交換” https://developer.uber.com/v1/auth/ 。 我也面臨一些問題,但至少我沒有得到400的回報:-)。
馬特
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.