2013-04-10 92 views
0

尝试在组织中设置oauth时,获取状态码302.
下面是代码片段。Salesforce Oauth状态代码302

String AUTH_URL = 'https://login.salesforce.com/services/oauth2/authorize'; 
String redirect_uri = 'https://login.salesforce.com/services/oauth2/success'; 
String response_type = 'token'; 
String client_id = 'xxxxxxxxxxxxxx.xxxxxxxxx'; 

authURL = AUTH_URL + 
     '?response_type=' + response_type + 
     '&client_id=' + client_id + 
     '&redirect_uri=' + redirect_uri; 

HttpRequest req = new HttpRequest(); 
HttpResponse res = new HttpResponse(); 
Http http = new Http(); 

req.setMethod('GET'); 
req.setEndpoint(authUrl); 
res = http.send(req); 

//结果:

res.getStatusCode()= 302个
res.getStatus()=找到

我期待着接受访问令牌和响应身体刷新令牌,但它是空的。
请建议我是否错过了某些东西。
在此先感谢。

回答

0

授权端点用于基于浏览器的交互式登录,而不是程序化登录。如果您想要一个纯粹的编程方法,那么您应该检出可以通过/ services/oauth2/token端点使用的用户名/密码oauth流。

+0

感谢您的帮助。我们不愿意使用用户名/密码流,因为我们不想公开用户密码。但它似乎是最后的胜地。再次感谢。干杯 – 2013-04-12 06:41:57