gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 20:28:08 29 4
gpt4 key购买 nike

服务器收到 one-time authorization code从移动应用程序。我需要将其转换为 spring-social 访问 token 和刷新 token ,并将它们保存在服务器数据库中供以后使用。

我当前的代码:

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();

oneTimeAuthorizationCode 是错误的,因为 ConnectionData 需要访问 token 而不是一次性授权代码。知道如何让 spring-social-google 将一次性代码交换为访问 token 和刷新 token 吗?

最佳答案

这是为访问 token 交换授权码的代码

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

关于java - Spring Social Google - 将一次性授权代码转换为服务器上的访问 token /刷新 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25565238/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com