Skip to content

Instantly share code, notes, and snippets.

@shrutis22
Created November 18, 2017 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shrutis22/ea0bfd1b02199ddec8ef17fb659656fb to your computer and use it in GitHub Desktop.
Save shrutis22/ea0bfd1b02199ddec8ef17fb659656fb to your computer and use it in GitHub Desktop.
This class is created for using the Google Service APIs from Salesforce.
/**
* This class is created for using
* the Google Service APIs from
* Salesforce.
*
* @author Shruti Sridharan
* @since 18.10.2017
* @revisions N/A
**/
public class GDriveForSalesforceCtrl {
/**
* This property is created to for
* getting the access token.
**/
public static String accessToken {
get {
Google_Settings__c settings = Google_Settings__c.getOrgDefaults();
Auth.JWT jwt = new Auth.JWT();
jwt.setAud( settings.Token_Endpoint__c );
jwt.setIss( settings.Service_Account_Id__c );
jwt.setAdditionalClaims( new Map<String, Object>{ 'scope' => settings.Scopes__c } );
Auth.JWS jws = new Auth.JWS( jwt, 'GDriveForSalesforce' );
Auth.JWTBearerTokenExchange bearer = new Auth.JWTBearerTokenExchange( settings.Token_Endpoint__c, jws );
return bearer.getAccessToken();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment