简体   繁体   English

带有 spring security 5 和 oauth2 的日历客户端

[英]Calendar client with spring security 5 and oauth2

I managed to configure google spring security 5 with outh2 to connect to google.我设法使用 outh2 配置 google spring security 5 以连接到 google。 I have the ability to save access_token.我有能力保存 access_token。 In the first step of my application we do not request calendar permissions.在我的应用程序的第一步中,我们不请求日历权限。 We do not want to obtain them until later.我们不想在以后获得它们。 I have seen many strange examples using webClient, resttemplate, examples that are already deprected.我见过很多奇怪的例子,使用 webClient、resttemplate、已经弃用的例子。

I am looking for a solution where I can use access_token and refresh_token for the application to request access to the calendar, and then I can download eg events.我正在寻找一种解决方案,我可以使用 access_token 和 refresh_token 为应用程序请求访问日历,然后我可以下载例如事件。

I am using a reactjs.我正在使用 reactjs。 I would like it to redirect me to the google site to give me permission and then be able to download events after another click on the front page.我希望它能够将我重定向到 google 站点以授予我权限,然后在再次单击首页后能够下载事件。

EDIT: Answer is:编辑:答案是:

Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod());
        credential.setAccessToken("your token");
        credential.setRefreshToken("your refresh token");
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        client = new com.google.api.services.calendar.Calendar.Builder(httpTransport, JSON_FACTORY, credential)
                .setApplicationName(APPLICATION_NAME).build();

Google supports incremental authorization , so if you initiate the OAuth flow again with the new permissions and the include_granted_scopes parameter set to true, you can add the new permissions onto your existing authorization. Google 支持增量授权,因此如果您使用新权限再次启动 OAuth 流程并且include_granted_scopes参数设置为 true,您可以将新权限添加到现有授权中。

Alternatively, you can use a managed solution like Xkit to add this kind of integration.或者,您可以使用像Xkit这样的托管解决方案来添加这种集成。 It handles the OAuth flow for you (with incremental authorization built in) as well as refresh tokens, and it integrates natively with React.它为您处理 OAuth 流程(内置增量授权)以及刷新令牌,并与 React 本地集成。 (Disclosure: I work there!) (披露:我在那里工作!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM