accesstoken

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)) .

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 Updated on June 22, 2024 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. Usage Create the Service Account and retrieve JSON file. Put Scopes, private_key and client_email as an object. If you want to use impersonate email, please set the value of impersonate_email. Run the script. /** * ### Description * Get access token from service account.

Directly Using Access Token by googleapis for Node.js

Gists This sample script is for directly using the refreshed access token by googleapis for Node.js. When oauth2Client.refreshAccessToken((err, tokens) => {}); is used to retrieve the refreshed access token, the following error occurs. DeprecationWarning: The refreshAccess Token method has been deprecated, and will be removed in the 3.0 release of goo gle-auth-library. Please use the getRequestHeaders method instead. It is required to use getRequestHeaders(). But I couldn’t find the sample script using getRequestHeaders().

Remove Third-party Apps with Account Access using Google Apps Script

Gists Overview This is a method for removing Third-party Apps with Account Access using a script. Demo Description When users create a script in a project and run the script, if the methods which are required to use scopes are included, users have to authorize to use the scopes using the browser. By authorizing it, users can use the script. The authorized projects can be seen at Third-party Apps with Account Access.