2016-10-13 176 views
1

我是Oauth的新手,我使用Spring Oauth2与xml 配置一起使用。从 http://www.beingjavaguys.com/2014/10/spring-security-oauth2-integration.htmlSpring oauth2授权提供商

所以下面的URL所取出的参考,以获得令牌是

http://localhost:8080/SpringRestSecurityOauth/oauth/token?grant_type=password&client_id=restapp&client_secret=restapp&username=beingjavaguys&[email protected] 

它给人的令牌reseponse。 所以在请求url中,client_id在xml文件中被硬编码。我想在运行时发送clientId,grantType。 这里需要注意哪些事情。

回答

0

通常情况下,你会发送client_id/client_secret头。

如果使用https,因为有秘密数据传输,OAuth2才是安全的。

这里一个例子(angularjs):

auth = 'Basic ' + window.btoa(client_id + ':' + client_secret); 
    $http.defaults.headers.common.Authorization = auth; 
    $http.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 
    grantparam= 'grant_type=password&username='+loginData.username + '&password=' + loginData.password; 
    $http.post('https://localhost:8123/oauth/token?'+grantparam) 

在这里从卷曲邮递员:

curl -X POST -H "Accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Basic 111111111111111" -H "Cache-Control: no-cache" -H "Postman-Token: 11111111-111111111111111" "https://localhost:8443/sf/api/oauth/token?grant_type=password&username=11111111111&password=**********"