JSFiddle - React, Tailwind, and code Playground

by Josh Pullen

JavaScript

/*

JWT Format:
{
	"alg": "RS256",
  "typ": "JWT"
}

{
  "iss": "[email protected]",
  "scope": "https://www.googleapis.com/auth/drive",
  "aud": "https://oauth2.googleapis.com/token",
  "exp": new Date().getTime() / 1000 + 3600,
  "iat": new Date().getTime() / 1000
}

-- Private key --

*/

(async function() {
  const formData = new FormData();
  formData.append("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer");
  formData.append("assertion", "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnYW1lbWFrZXJAdGV0cmlzLXByZWVkZXJib2FyZC5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsInNjb3BlIjoiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vYXV0aC9kcml2ZSIsImF1ZCI6Imh0dHBzOi8vb2F1dGgyLmdvb2dsZWFwaXMuY29tL3Rva2VuIiwiZXhwIjoxNTgzNzkyNDgyLCJpYXQiOjE1ODM3ODg4ODR9.k2IHnR6O1jUFU8Il3PAfuNfQLgwV0mdOvQlmCnqB5yanl-_DWPH0s2OZcDjXagPEIOoWDWUHsr-ZQNZZYIfSXj4e4T5PD3gzbz8Oa97tcaVWlPRE8k056wgVvxAu7B0yhBN0Dw7BIiI7Lsd5nYHe1T969LBvKe5wgX8euIUK9QEheMpM1rV1Fllabm8cnjHc2M7eC0yesMSgaeKtKczAZdepuPp39wekkGaMOQT2lrMAmv-q2B_d4EPvPoHD-c75fKLBc37ZJd3TPCSn9AId1Skoh4zj7PyPf8e4f9SxocY5gzWVqd8LI6YDO9aDYH5GsdTpmbeG7vWU6cjgZXkBIA");

  const client_token = await fetch("https://oauth2.googleapis.com/token", {
    method: "POST",
    body: formData
  })
  .then(res => res.json())
  .then(res => res.access_token);

  console.log(client_token);
  
  fetch(`https://www.googleapis.com/drive/v3/about?client_token=${client_token}`)
})();