Java 无法为访问令牌交换OAuth身份验证代码
我只是想制作一个简单的应用程序,但我甚至无法通过对用户的身份验证。我正在使用Google OAuth Java客户端库。Java 无法为访问令牌交换OAuth身份验证代码,java,google-cloud-platform,google-oauth,google-oauth-java-client,Java,Google Cloud Platform,Google Oauth,Google Oauth Java Client,我只是想制作一个简单的应用程序,但我甚至无法通过对用户的身份验证。我正在使用Google OAuth Java客户端库。 以下是我目前正在采取的步骤: 启动本地web服务器以在OAuth身份验证后侦听环回响应 生成身份验证URL: String url = new AuthorizationCodeRequestUrl(AUTH_URL, CLIENT_ID) .setScopes(scopes) // Contains https://www.googleapis.com
以下是我目前正在采取的步骤:
String url = new AuthorizationCodeRequestUrl(AUTH_URL, CLIENT_ID)
.setScopes(scopes) // Contains https://www.googleapis.com/auth/drive.readonly
.setRedirectUri(LOCALHOST + r.getPort()) // Port of local web server
.build();
TokenResponse token = new AuthorizationCodeTokenRequest(...)
.setRedirectUri("http://localhost") // <--
.setClientAuthentication(getClientAuth()) // ClientParametersAuthentication object
.execute();
TokenResponse token=new AuthorizationCodeTokenRequest(…)
.setRedirectUri(“http://localhost“”/事实证明,身份验证代码和访问令牌必须使用相同的重定向uri
,即使它不用于检索访问令牌
TokenResponse token = new AuthorizationCodeTokenRequest(...)
.setRedirectUri("http://localhost") // <--
.setClientAuthentication(getClientAuth()) // ClientParametersAuthentication object
.execute();