Skip to content

Instantly share code, notes, and snippets.

@maniankara
Forked from eruffaldi/gettoken.sh
Last active January 7, 2024 16:18
Show Gist options
  • Select an option

  • Save maniankara/47e5debe9008abe15e6bcff99d550fe2 to your computer and use it in GitHub Desktop.

Select an option

Save maniankara/47e5debe9008abe15e6bcff99d550fe2 to your computer and use it in GitHub Desktop.

Revisions

  1. Anoop Vijayan Maniankara revised this gist Jan 7, 2024. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions gettoken.sh
    Original file line number Diff line number Diff line change
    @@ -9,8 +9,7 @@ client_secret="...."
    #2) get authorization code at the following link using web browser
    # OUTPUT: code
    scopes="https://www.googleapis.com/auth/admin.directory.user,https://www.googleapis.com/auth/admin.directory.user.readonly"
    scope="https://www.googleapis.com/auth/drive"
    url="https://accounts.google.com/o/oauth2/auth?client_id=$client_id&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=$scope&response_type=code"
    url="https://accounts.google.com/o/oauth2/auth?client_id=$client_id&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=$scopes&response_type=code"
    code="..."

    #3) use the code to obtain a OAuth2.0 Token
  2. Anoop Vijayan Maniankara revised this gist Jan 7, 2024. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions gettoken.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    #!/bin/bash
    # Bash script for generating OAuth token for Google admin user fetching

    #1) on https://console.developers.google.com/ register project and associate API from library
    # OUTPUT: client_id,client_secret
    @@ -7,6 +8,7 @@ client_secret="...."

    #2) get authorization code at the following link using web browser
    # OUTPUT: code
    scopes="https://www.googleapis.com/auth/admin.directory.user,https://www.googleapis.com/auth/admin.directory.user.readonly"
    scope="https://www.googleapis.com/auth/drive"
    url="https://accounts.google.com/o/oauth2/auth?client_id=$client_id&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=$scope&response_type=code"
    code="..."
    @@ -24,7 +26,7 @@ curl --request POST --data "client_id=$client_id&client_secret=$client_secret&re
    curl "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=$token"

    #6) use the token in a specific API (assed ass access_token=$token)
    docid="...."
    curl "https://docs.google.com/spreadsheets/d/$docid/export?format=csv&access_token=$token"
    #docid="...."
    #curl "https://docs.google.com/spreadsheets/d/$docid/export?format=csv&access_token=$token"


  3. Anoop Vijayan Maniankara revised this gist Jan 7, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gettoken.sh
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ refresh_token="..."
    token="..."

    #4) refresh if needed
    curl --request POST --data "--data 'client_id=$client_id&client_secret=$client_secret&refresh_token=$refresh_token&grant_type=refresh_token" https://accounts.google.com/o/oauth2/token
    curl --request POST --data "client_id=$client_id&client_secret=$client_secret&refresh_token=$refresh_token&grant_type=refresh_token" https://accounts.google.com/o/oauth2/token

    #5) get status of token
    curl "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=$token"
  4. @eruffaldi eruffaldi revised this gist Sep 25, 2018. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions gettoken.sh
    Original file line number Diff line number Diff line change
    @@ -4,20 +4,25 @@
    # OUTPUT: client_id,client_secret
    client_id="..."
    client_secret="...."

    #2) get authorization code at the following link using web browser
    # OUTPUT: code
    scope="https://www.googleapis.com/auth/drive"
    url="https://accounts.google.com/o/oauth2/auth?client_id=$client_id&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=$scope&response_type=code"
    #3) use the code to obtain a OAuth2.0 Token
    code="..."

    #3) use the code to obtain a OAuth2.0 Token
    # OUTPUT: token and refresh_token in JSON
    curl --request POST --data "code=$code&client_id=$client_id&client_secret=$client_secret&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code" https://accounts.google.com/o/oauth2/token
    #4) refresh if needed
    refresh_token="..."
    token="..."

    #4) refresh if needed
    curl --request POST --data "--data 'client_id=$client_id&client_secret=$client_secret&refresh_token=$refresh_token&grant_type=refresh_token" https://accounts.google.com/o/oauth2/token

    #5) get status of token
    curl "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=$token"

    #6) use the token in a specific API (assed ass access_token=$token)
    docid="...."
    curl "https://docs.google.com/spreadsheets/d/$docid/export?format=csv&access_token=$token"
  5. @eruffaldi eruffaldi created this gist Sep 25, 2018.
    25 changes: 25 additions & 0 deletions gettoken.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/bin/bash

    #1) on https://console.developers.google.com/ register project and associate API from library
    # OUTPUT: client_id,client_secret
    client_id="..."
    client_secret="...."
    #2) get authorization code at the following link using web browser
    # OUTPUT: code
    scope="https://www.googleapis.com/auth/drive"
    url="https://accounts.google.com/o/oauth2/auth?client_id=$client_id&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=$scope&response_type=code"
    #3) use the code to obtain a OAuth2.0 Token
    code="..."
    # OUTPUT: token and refresh_token in JSON
    curl --request POST --data "code=$code&client_id=$client_id&client_secret=$client_secret&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code" https://accounts.google.com/o/oauth2/token
    #4) refresh if needed
    refresh_token="..."
    token="..."
    curl --request POST --data "--data 'client_id=$client_id&client_secret=$client_secret&refresh_token=$refresh_token&grant_type=refresh_token" https://accounts.google.com/o/oauth2/token
    #5) get status of token
    curl "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=$token"
    #6) use the token in a specific API (assed ass access_token=$token)
    docid="...."
    curl "https://docs.google.com/spreadsheets/d/$docid/export?format=csv&access_token=$token"