DocuSign in a Java Spring Boot backend and a Vue.js frontend. The goal is to allow a user to authenticate via OAuth, obtain an access token, and use it to interact with the DocuSign API.
1. Backend (Java Spring Boot)
In the backend, we will handle the OAuth flow, exchange the authorization code for an access token, and return the token to the frontend.
1.1 Spring Boot Controller for OAuth Authentication
package com.example.docusign.controller; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.*; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @RestController @RequestMapping("/api/docusign") public class DocuSignController { @Value("${docusign.client.id}") private String clientId; @Value("${docusign.client.secret}") private String clientSecret; @Value("${docusign.redirect.uri}") private String redirectUri; @PostMapping("/authenticate") public ResponseEntity<?> authenticate(@RequestBody AuthRequest authRequest) { String code = authRequest.getCode(); String tokenUrl = "https://account-d.docusign.com/oauth/token"; // Prepare the form parameters for the token exchange String formParams = "grant_type=authorization_code&code=" + code + "&redirect_uri=" + redirectUri; // Prepare headers HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); // Base64 encode the clientId and clientSecret String auth = clientId + ":" + clientSecret; String encodedAuth = "Basic " + java.util