我正在尝试在服务器端实现Google登录,而我正在调用的API是 https://accounts.google.com/o/oauth2/auth?。如果我直接从浏览器中调用它,它将使用代码作为请求参数将我重定向到我的redirect_uri,但是如果我从后端作为rest webservice运行它,尽管响应为200,它也不会做任何事情
后端代码:
public void oauth2Service(){
OkHttpClient client = new OkHttpClient();
StringBuilder oauth2GetCodeUrl = new StringBuilder();
oauth2GetCodeUrl.append(env.getProperty("oauth2_url"));
oauth2GetCodeUrl.append("scope=").append(getGoogleSignInProperties.getScope());
oauth2GetCodeUrl.append("&redirect_uri=").append(getGoogleSignInProperties.getRedirect_uri());
oauth2GetCodeUrl.append("&response_type=").append(getGoogleSignInProperties.getResponse_id());
oauth2GetCodeUrl.append("&client_id=").append(getGoogleSignInProperties.getClient_id());
oauth2GetCodeUrl.append("&approval_prompt=").append(getGoogleSignInProperties.getApproval_prompt());
Request request = new Request.Builder()
.url(oauth2GetCodeUrl.toString()).get()
.addHeader("content-type", "application/x-www-form-urlencoded")
.addHeader("cache-control", "no-cache")
.build();
try {
Response response = client.newCall(request).execute();
System.out.println(response.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
api应该将我重定向到请求中已经提到的重定向URI