From 703995f959fb65ceabe0817da0333238dbc03db8 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Mon, 21 Apr 2025 22:13:38 +0200 Subject: [PATCH] zoho oauth grant service added --- doc/zoho/README.md | 36 ++++++ .../zoho/ZohoOAuthGrantService.java | 108 ++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 doc/zoho/README.md create mode 100644 office-alexander-logistics-app/src/main/java/com/alexanderlogistics/zoho/ZohoOAuthGrantService.java diff --git a/doc/zoho/README.md b/doc/zoho/README.md new file mode 100644 index 0000000..2457968 --- /dev/null +++ b/doc/zoho/README.md @@ -0,0 +1,36 @@ +# Zoho Web API + +AGL Dubai nutzt Zoho als Platform zusammen mit einer lokalen Steuerkanzlei + +## Test/Prod Account Imixs + +https://api-console.zoho.eu/ +https://api-console.zoho.eu/client/1000.NLTM2KUEHI696MSLGEIANATVGGX7IN + +``` +client ID= 1000.NLTM2KUEHI696MSLGEIANATVGGX7IN +client secret= ee9ba49f16e77c64abb89cea13542d2326d8d03ce8 +``` + +# Testumgebung + +https://books.zoho.eu/app/20105697367 +https://accounts.zoho.eu/home# + +API Docu: + +https://www.zoho.com/books/api/v3/introduction/ + +Authentication: + +https://www.zoho.com/books/api/v3/oauth/ + +Base API URI= https://accounts.zoho.eu/ + +## 1. Generating Grant Token + +https://accounts.zoho.com/oauth/v2/auth?scope=ZohoBooks.invoices.CREATE,ZohoBooks.invoices.READ,ZohoBooks.invoices.UPDATE,ZohoBooks.invoices.DELETE&client_id=1000.NLTM2KUEHI696MSLGEIANATVGGX7IN&state=testing&response_type=code&redirect_uri=https://alexander-logistics-dwc.office-workflow.de/ + +## 2. Generate Access and Refresh Token + +https://accounts.zoho.com/oauth/v2/token?code=1000.dd7exxxxxxxxxxxxxxxxxxxxxxxx9bb8.b6c0xxxxxxxxxxxxxxxxxxxxxxxxdca4&client_id=1000.NLTM2KUEHI696MSLGEIANATVGGX7IN&client_secret=ee9ba49f16e77c64abb89cea13542d2326d8d03ce8&redirect_uri=http://www.zoho.com/books&grant_type=authorization_code diff --git a/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/zoho/ZohoOAuthGrantService.java b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/zoho/ZohoOAuthGrantService.java new file mode 100644 index 0000000..4e464cb --- /dev/null +++ b/office-alexander-logistics-app/src/main/java/com/alexanderlogistics/zoho/ZohoOAuthGrantService.java @@ -0,0 +1,108 @@ +/* + * Imixs-Workflow + * + * Copyright (C) 2001-2020 Imixs Software Solutions GmbH, + * http://www.imixs.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You can receive a copy of the GNU General Public + * License at http://www.gnu.org/licenses/gpl.html + * + * Project: + * https://www.imixs.org + * https://github.com/imixs/imixs-workflow + * + * Contributors: + * Imixs Software Solutions GmbH - Project Management + * Ralph Soika - Software Developer + */ + +package com.alexanderlogistics.zoho; + +import java.util.logging.Logger; + +import org.imixs.workflow.exceptions.QueryException; + +import jakarta.annotation.Resource; +import jakarta.ejb.SessionContext; +import jakarta.ejb.Stateless; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Context; +import jakarta.ws.rs.core.MediaType; + +/** + * Dieser API Endpoint dient dazu über zoho einen sogenannten Grant Token zu + * erhalten. + * + * https://www.zoho.com/books/api/v3/oauth/ + * + * Er dient als redirect URL wenn jemand einen solchen Token über den Browser + * anfordert. + * Der URL muss hier als CallBack URL angegeben sein! + * + * Beispiel: + * + * https://accounts.zoho.com/oauth/v2/auth?scope=ZohoBooks.invoices.CREATE,ZohoBooks.invoices.READ,ZohoBooks.invoices.UPDATE,ZohoBooks.invoices.DELETE&client_id=1000.NLTM2KUEHI696MSLGEIANATVGGX7IN&state=testing&response_type=code&redirect_uri=https://alexander-logistics-dwc.office-workflow.de/api/zoho/grant + * + * @version 1.0 + * @author rsoika + * + */ +@Path("/zoho") +@Stateless +public class ZohoOAuthGrantService { + + @Context + private HttpServletRequest servletRequest; + + @Context + HttpServletResponse servletResponse; + + @Resource + private SessionContext ctx; + + private static Logger logger = Logger.getLogger(ZohoOAuthGrantService.class.getName()); + + @GET + @Path("/ping") + public String ping() { + logger.info("GET ping"); + return "ping: " + System.currentTimeMillis(); + } + + /** + * Test method + * + * @param workflowgroup + * @param task + * @return + * @throws QueryException + */ + @GET + @Path("/grant") + @Produces({ MediaType.TEXT_HTML }) + public String getGrantToken() + throws QueryException { + + logger.info("├── Receive Grant Token from Zoho"); + String baseURI = servletRequest.getRequestURL().toString(); + + logger.info("│ ├── Base URI=" + baseURI); + + return "Zoho Grant Token received!"; + } + +}