问题描述
我正在尝试使用 google java OAuth 2.0 库,并且大部分情况下一切正常,但是我在尝试连接到 oauth 端点时遇到了一些奇怪的间歇性错误,我在公司论坛上看到它可能与范围的构建方式有关,所以有什么方法可以查看所有请求参数吗?如:
POST token_server_url/token
Authorization: Basic xxxx
Content-Type: application/application/x-www-form-urlencoded
grant_type=authorization_code&code=mypermissioncode&redirect_uri=http://localhost
等等,基本上都是头和payload
下面是我的代码:
@Override
public AuthorizationCodeFlow getAuthorizationCodeFlow(DataStoreFactory dataStoreFactory) throws IOException {
AuthorizationCodeFlow flow = new AuthorizationCodeFlow.Builder(BearerToken.authorizationHeaderAccessMethod(),HTTP_TRANSPORT,JSON_FACTORY,new GenericUrl(tokenServerUrl),new ClientParametersAuthentication(clientId,clientSecret),clientId,authServerUrl)
.setScopes(scopes)
.setDataStoreFactory(dataStoreFactory)
.build();
return flow;
}
@Override
public String getNewAuthWorkflowUrl(DataStoreFactory dataStoreFactory,String secretState) throws IOException {
AuthorizationCodeFlow flow = getAuthorizationCodeFlow(dataStoreFactory);
return flow.newAuthorizationUrl().setClientId(clientId).setScopes(scopes).setState(secretState)
.setRedirectUri(redirectUrl).build();
}
private TokenResponse fetchNewTokenResponse(String code) throws Exception {
DataStoreFactory DATA_STORE_FACTORY = new MemoryDataStoreFactory();
AuthorizationCodeFlow flow = getAuthorizationCodeFlow(DATA_STORE_FACTORY);
AuthorizationCodetokenRequest req = flow.newTokenRequest(code).setRedirectUri(redirectUrl);
// how to see request parameters here
return req.execute();
}
private TokenResponse fetchRefreshTokenResponse(BusinessApiTokenDto refreshToken)
throws IOException {
return new RefreshTokenRequest(HTTP_TRANSPORT,refreshToken.tokenValue)
.setClientAuthentication(new BasicAuthentication(clientId,clientSecret))
.execute();
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)