Spring Social Google - 将一次性授权代码转换为服务器上的访问令牌/刷新令牌

che*_*ist 5 java spring google-login spring-social spring-social-google

服务器从移动应用程序接收一次性授权代码.我需要将其转换为spring-social访问令牌并刷新令牌并将其保存在服务器数据库中以供以后使用.

我目前的代码:

String oneTimeAuthorizationCode= "xxx"; // provided by mobile client

ConnectionData cd = new ConnectionData("google", null, null, null, null, oneTimeAuthorizationCode, null, null, null);
GoogleConnectionFactory googleConnectionFactory = (GoogleConnectionFactory) connectionFactoryLocator.getConnectionFactory("google");
Connection<Google> connection = googleConnectionFactory.createConnection(cd);

// get the google API and work with it
Google  google = (Google) connection.getApi();
Run Code Online (Sandbox Code Playgroud)

oneTimeAuthorizationCode是错误的,因为ConnectionData期望访问令牌而不是一次授权代码.任何想法如何让spring-social-google交换访问令牌的一次性代码并刷新令牌?

小智 2

这是用于交换访问令牌的授权代码的代码

String authorizationcode=*****;
auth2Operations = googleConnectionFactory.getOAuthOperations();
AccessGrant accessGrant =auth2Operations.exchangeForAccess(authorizationcode,"Your      redirect uri",null);
connection = googleConnectionFactory.createConnection(accessGrant);
Google google=connection.getApi();
Run Code Online (Sandbox Code Playgroud)