خرید بک لینک

Vote count: 0

Hi I am implementing Spring Oauth 2 framework in my project, i am getting 401 unauthorized error when requesting for access token, below is my code.

public class Test {


    public static void main(String[] args) {

        RestTemplate restTemplate=new RestTemplate();
        Map<String, String> map=new HashMap<String, String>();
        map.put("grant_type", "password");
        map.put("client_id", "test");
        map.put("client_secret", "test");
        map.put("useame", "test");
        map.put("password", "test");
        String url="http://localhost:8080/SpringOauthServer/oauth/token?grant_type={grant_type}&client_id={client_id}&client_secret={client_secret}&useame={useame}&password={password}";

        OauthToken result=restTemplate.getForObject(url, OauthToken.class,map);     
        System.out.println(result.getAccess_token());
    }


}

but when i use below curl command i get the access token. please help me where i am mistaking..

curl test:test@localhost:8080/SpringOauthServer/oauth/token -d grant_type=password -d client_id=test -d client_secret=test -d useame=test   -d password=test

Response:

{
   "access_token":"d83a312b-323a-40a9-bfc4-c431c40f2ca8",
   "token_type":"bearer",
   "refresh_token":"17976f94-f3b7-4e2d-8726-3d094f7b1061",
   "expires_in":43190,
   "scope":"read write trust"
}

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 27 ارديبهشت 1395 ساعت: 0:28

صفحه بندی