Compare commits

...

3 Commits
master ... gapi

Author SHA1 Message Date
AJ ONeal 5db5fcb5e6 drive perms 4 years ago
AJ ONeal 0df4535e17 more scopes and tokens and lists 5 years ago
AJ ONeal 86e605f265 WIP: add basic stuff 5 years ago
  1. 60
      public/app.js
  2. 17
      public/index.html

60
public/app.js

@ -0,0 +1,60 @@
'use strict';
// https://developers.google.com/sheets/api/guides/authorizing
// https://www.googleapis.com/auth/spreadsheets.readonly
// Scope names
// https://developers.google.com/drive/api/v3/about-auth
// Google Sheets API
// https://developers.google.com/sheets/api/guides/migration#list_spreadsheets_for_the_authenticated_user
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
var id_token = googleUser.getAuthResponse().id_token;
var access_token = googleUser.getAuthResponse();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
console.log('access_token', access_token);
console.log('id_token', id_token);
window
.fetch('https://oauth2.googleapis.com/tokeninfo?id_token=' + id_token)
.then(function(resp) {
return resp.json().then(function(data) {
console.log(data);
});
});
/*
window
.fetch(
"https://www.googleapis.com/drive/v3/files?q=mimeType%3D'application%2Fvnd.google-apps.spreadsheet'",
{
headers: {Authorization: 'Bearer ' + access_token.access_token},
},
)
.then(function(resp) {
return resp.json().then(function(data) {
console.log(data);
});
});
window
.fetch('https://spreadsheets.google.com/feeds/spreadsheets/private/full', {
headers: {Authorization: 'Bearer ' + access_token.access_token},
})
.then(function(resp) {
return resp.json().then(function(data) {
console.log(data);
});
});
*/
}
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function() {
console.log('User signed out.');
});
}

17
public/index.html

@ -1,3 +1,11 @@
<meta
name="google-signin-client_id"
content="128764648444-nk2ss16gmals7rhsk2kj0i0ove0v0tnk.apps.googleusercontent.com"
/>
<!-- https://developers.google.com/identity/sign-in/web/sign-in -->
<!-- https://developers.google.com/identity/sign-in/web/quick-migration-guide -->
<!-- Note: You can also specify your app's client ID with the client_id parameter of the gapi.auth2.init() method. -->
<pre><code>
<h1>Tokens for Testing</h1>
Compatible with
@ -105,3 +113,12 @@ You shouldn't use it for automated testing, because it will change, but it looks
}
</code></pre>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<div
class="g-signin2"
data-onsuccess="onSignIn"
data-scope="profile email https://www.googleapis.com/auth/spreadsheets.readonly https://www.googleapis.com/auth/drive.readonly"
></div>
<a href="#" onclick="signOut();">Sign out</a>
<script src="app.js"></script>

Loading…
Cancel
Save