Service Account

Using Google API Client Library (gapi) for JavaScript with Service Account

Gists This is a sample script for using Google API Client Library (gapi) for JavaScript with the service account. Unfortunately, in the current stage, gapi cannot directly use the service account. So, in this case, it is required to implement the script for retrieving the access token from the service account. In this report, I would like to introduce the method for using gapi with the service account using a Javascript library.

Javascript library - GetAccessTokenFromServiceAccount_js

Overview This is a Javascript library to retrieve the access token from the Google Service Account. Ref Description I have already posted the sample script for retrieving the access token from the Google Service Account. Ref But, when I use this script, I thought that when this was published as the Javascript library, it will be useful. So I created this. Install <script src="getaccesstokengromserviceaccount_js.min.js"></script> Or, using jsdelivr cdn <script src="https://cdn.jsdelivr.net/gh/tanaikech/GetAccessTokenFromServiceAccount_js@master/getaccesstokengromserviceaccount_js.min.js"></script> You can see the detail of this at https://github.

Retrieving Access Token using Service Account for PHP without using googleapis

Gists This is a sample PHP script to retrieve the access token from Service Account of Google without using googleapis. Sample script <?php $private_key = "-----BEGIN PRIVATE KEY-----\n###-----END PRIVATE KEY-----\n"; // private_key of JSON file retrieved by creating Service Account $client_email = "###"; // client_email of JSON file retrieved by creating Service Account $scopes = ["https://www.googleapis.com/auth/drive.readonly"]; // Sample scope $url = "https://www.googleapis.com/oauth2/v4/token"; $header = array("alg" => "RS256", "typ" => "JWT"); $now = floor(time()); $claim = array( "iss" => $client_email, "sub" => $client_email, "scope" => implode(" ", $scopes), "aud" => $url, "exp" => (string)($now + 3600), "iat" => (string)$now, ); $signature = base64_encode(json_encode($header, JSON_UNESCAPED_SLASHES)) .

Safe-Uploading for Google Drive by HTML in External Server using Google Apps Script

Overview This is a report for safe-uploading files to Google Drive by HTML put in the external server using Google Apps Script. Description When you want to make the user upload a file to your own Google Drive using the HTML put in the external server of Google side, when the file size is smaller than 50 MB, this can be achieved without using the access token. Ref (When the HTML is put in the internal server of Google side, you can also use google.

Retrieving Access Token for Service Account using Javascript

Gists This is a sample script for retrieving the access token for Service Account using Javascript. The flow for using this script is as follows. At first, please create the Service Account and retrieve JSON file. Put Scopes, private_key and client_email to the script. Run the script. Sample script In this script, 2 libraries of jsencrypt and crypto-js are used. <script src="https://cdnjs.cloudflare.com/ajax/libs/jsencrypt/3.0.0-rc.1/jsencrypt.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js"></script> <script> async function sample() { const private_key = "###"; // private_key of JSON file retrieved by creating Service Account const client_email = "###"; // client_email of JSON file retrieved by creating Service Account const scopes = ["https://www.

Retrieving Access Token using Service Account for Node.js without using googleapis

Gists This is a sample Node.js script to retrieve access token from Service Account of Google without using googleapis. const cryptor = require('crypto'); const request = require('request'); const privateKey = "###"; // private_key of JSON file retrieved by creating Service Account const clientEmail = "###"; // client_email of JSON file retrieved by creating Service Account const scopes = ["https://www.googleapis.com/auth/drive.readonly"]; // Sample scope const url = "https://www.googleapis.com/oauth2/v4/token"; const header = { alg: "RS256", typ: "JWT", }; const now = Math.

Retrieving Access Token using Service Account by Google's OAuth2 package for Golang

Gists This is a sample golang script for retrieving access token using Service Account of Google by Google’s OAuth2 package. The script without using Google’s OAuth2 package is here. package main import ( "encoding/json" "fmt" "io/ioutil" "os" "golang.org/x/oauth2" "golang.org/x/oauth2/google" "golang.org/x/oauth2/jwt" ) func serviceAccount(credentialFile string) (*oauth2.Token, error) { b, err := ioutil.ReadFile(credentialFile) if err != nil { return nil, err } var c = struct { Email string `json:"client_email"` PrivateKey string `json:"private_key"` }{} json.

Retrieving Access Token for Service Account using Google Apps Script

Gists This is a sample script for retrieving the access token for Service Account using Google Apps Script. The flow for using this script is as follows. At first, please create the Service Account and retrieve JSON file. Put Scopes, private_key and client_email to the script. Run the script. var private_key = "#####"; // private_key of JSON file retrieved by creating Service Account var client_email = "#####"; // client_email of JSON file retrieved by creating Service Account var scopes = ["https://www.