Class GoogleAuthenticator
Wrapper class for interaction with Google's API and authentication methods. This is designed to handle all user authentication and returning of Google API Client classes in an easy to use manner. Much of the code is from Google's stock PHP API examples, but it has been modified to be usable with our software and as such some of the comments/classes are Google developers' not mine.
public
|
#
__construct( )
Constructor that sets up the Authenticator with all the required data to connect to Google properly. |
public
String
|
|
public
|
#
storeCredentials( Integer $userId, String $credentials )
Store OAuth 2.0 credentials in the application's database. |
public
String
|
#
exchangeCode( String $authorizationCode )
Exchange an authorization code for OAuth 2.0 credentials. |
public
Userinfo
|
#
getUserInfo( String $credentials )
Send a request to the UserInfo API to retrieve the user's information. |
public
String
|
|
public
String
|
#
getCredentials( String $authorizationCode, String $state )
Retrieve credentials using the provided authorization code. |
public
|
#
flushCredentials( boolean $full = true )
Sometimes, terrible things happen. When an auth error occurs or a problem with the credentials arises, flush every place they're stored immediately to stop any errors badly provided credentials may be causing. |
public
String|boolean
|
#
getAccessToken( Integer $userId = null )
This function is used to get the current access token. This function is vital to the class as it allows any code using the Authenticator to discover if a connection to Google has been made and if any actions connecting to Google can procede. This function is called in a large number of places as a gate to continuing integration tasks. |
public
|
|
public
|
|
public
|
|
public
|
public
string
|
$clientId | '' |
#
Client ID of the Google API Project |
public
string
|
$clientSecret | '' |
#
Client secret of the Google API Project |
public
string
|
$redirectUri | '' |
#
Redirect URI for the authentication request |
public
array
|
$scopes | array(
'https://www.googleapis.com/auth/plus.login', // Google+ login required to login with Google
'https://www.googleapis.com/auth/drive', // Drive required for drive integration
'https://www.googleapis.com/auth/userinfo.email', // Email required for Google login
'https://www.googleapis.com/auth/userinfo.profile', // Basic profile info required for Google login
'https://www.googleapis.com/auth/calendar', // Calendar required for Calendar sync
'https://www.googleapis.com/auth/calendar.readonly', // Read only Calendar required for Calendar list
) |
#
A list of scopes required by the Google API to use for Google Integration within the software. This list defines the permissions that Google will ask for when a user is authenticating with them and X2. |