}
private void parseToken(String jwt) throws OAuthException {
String [] sections = jwt.split("\\.");
if(sections.length != 3)
throw new OAuthException("An error occured while authenticating");
// No validation required since the token comes directly from the google server
// JWT Structure
// Header.Claim.Signature
String claim = sections[1];
int buffer = 4 - (claim.length() % 4);
// Encoded base64 should never need 3 buffer characters
if(buffer == 3)
throw new OAuthException("An error occured while authenticating");
// Don't add 4 buffer characters
for(int i = 0; i < buffer && buffer != 4; i++) {
claim += "=";
}
String decodedClaim = new String(Base64.decode(claim.getBytes()));
JSONObject jsonClaim;
try {
jsonClaim = new JSONObject(decodedClaim);
userId = jsonClaim.getString(ID_PARAMETER);
provider = jsonClaim.getString(PROVIDER_PARAMETER);
openid_id = jsonClaim.getString(OPEN_ID_PARAMETER);
} catch (JSONException e) {
throw new OAuthException(e);
}
email = "";
email_verified = false;
try{
email = jsonClaim.getString(EMAIL_PARAMETER);