Last active
August 29, 2015 14:19
-
-
Save richieforeman/0362fe19b4dfe8510c16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>JS Client Test Bench</title> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
var SETTINGS = { | |
CLIENT_ID: '801883730557-sm0htkeqruc79vm569f20gk8ponn62sv.apps.googleusercontent.com', | |
API_KEY: 'AIzaSyDobgkbnTo75Vb7XmgNBemxvbT_YKFTAPE', | |
SCOPES: 'https://www.googleapis.com/auth/plus.me' | |
}; | |
var JSLibTinker = function(window, gapi) { | |
/** @type {window} */ | |
this.window_ = window; | |
/** @type {object} */ | |
this.gapi_ = gapi; | |
this.gapi_.client.setApiKey(SETTINGS.API_KEY); | |
} | |
JSLibTinker.prototype.authenticate = function() { | |
this.gapi_.auth.authorize({ | |
client_id: SETTINGS.CLIENT_ID, | |
scope: SETTINGS.SCOPES, | |
// By requesting an 'offline' access token, we'll receive a refresh token | |
access_type: 'offline', | |
// By requested a code, rather than a token, we'll be able to pull the refresh token and store | |
// it for use in a backend application. | |
response_type: 'code' | |
}, function(authResult) { | |
console.log(authResult); | |
if (authResult && !authResult.error) { | |
this.handleAuthSuccess_(authResult).bind(this); | |
} else { | |
this.handleAuthFailure_(authResult).bind(this); | |
} | |
}.bind(this)); | |
}; | |
/** | |
* Handle Authentication success. | |
*/ | |
JSLibTinker.prototype.handleAuthSuccess_ = function(authResult) { | |
this.window_.alert('refreshToken=' + authResult.code); | |
console.log(authResult); | |
}; | |
/** | |
* Handle Authentication Failures. | |
*/ | |
JSLibTinker.prototype.handleAuthFailure_ = function(authResult) { | |
console.log(authResult); | |
}; | |
function handleClientLoad() { | |
var lib = new JSLibTinker(window, gapi); | |
lib.authenticate(); | |
} | |
</script> | |
<script src="//apis.google.com/js/client.js?onload=handleClientLoad"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment