Spring Outh2访问令牌异常
我正在spring boot应用程序中实现Outh2以进行身份验证。我成功地获取了授权代码,但当我通过rest模板向令牌url发出post请求时,它给了我异常400错误请求。通过此异常,我无法识别问题。下面是我的代码Spring Outh2访问令牌异常,spring,spring-boot,Spring,Spring Boot,我正在spring boot应用程序中实现Outh2以进行身份验证。我成功地获取了授权代码,但当我通过rest模板向令牌url发出post请求时,它给了我异常400错误请求。通过此异常,我无法识别问题。下面是我的代码 ResponseEntity<String> response = null; System.out.println("Authorization Ccode------" + code); RestTemplate r
ResponseEntity<String> response = null;
System.out.println("Authorization Ccode------" + code);
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity<String> request = new HttpEntity<String>(headers);
String access_token_url = "https://www.googleapis.com/oauth2/v3/token";
access_token_url += "?code=" + code;
access_token_url += "&client_id =487786082511-ta7fnptb8dnd4lbq9lphbtbpll9eo1it.apps.googleusercontent.com";
access_token_url += "&client_secret =fS4KHLUUMOm-lYu8QtDOFcDV";
access_token_url += "&grant_type=authorization_code";
access_token_url += "&redirect_uri=http://localhost:8080/salesgoal/googleOuth2Success";
try {
response = restTemplate.exchange(access_token_url, HttpMethod.POST, request, String.class);
}
catch(Exception e){
e.printStackTrace();
ResponseEntity response=null;
System.out.println(“授权代码-------”+代码);
RestTemplate RestTemplate=新RestTemplate();
HttpHeaders=新的HttpHeaders();
setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity请求=新的HttpEntity(标头);
字符串访问\u令牌\u url=”https://www.googleapis.com/oauth2/v3/token";
访问令牌url+=“?code=“+code;
访问“&client\u id=487786082511-ta7fnptb8dnd4lbq9lphbtbpl9eo1it.apps.googleusercontent.com”;
access_token_url+=“&client_secret=fS4KHLUUMOm-lYu8QtDOFcDV”;
访问\令牌\ url+=“&授予\类型=授权\代码”;
访问\u令牌\u url+=“&重定向\u uri=http://localhost:8080/salesgoal/googleOuth2Success";
试一试{
response=restemplate.exchange(访问\u令牌\u url,HttpMethod.POST,请求,String.class);
}
捕获(例外e){
e、 printStackTrace();
请让我知道我做错了什么。
感谢您关注谷歌的
client\u id
和client\u secret
)'Content-Type',application/x-www-form-urlencoded'
头来遵循oauth2规范请分享您的堆栈跟踪我的团队问题已得到解决,我想问题在于客户端id和客户端机密中的空间。