index
GoogleAuthService
- GoogleAuthService
- new GoogleAuthService()
- .getGapiClient() ⇒
Promise.<gapi> - .getAuthInstance() ⇒
Promise.<GoogleAuth> - .getCurrentUser() ⇒
Promise.<GoogleUser> - .getOfflineAccessCode() ⇒
string|null - .grantOfflineAccess() ⇒
Promise.<string> - .login([options]) ⇒
Promise.<LoginResponse> - .refreshToken() ⇒
Promise.<AuthResponse> - .grant() ⇒
Promise.<GoogleUser> - .logout() ⇒
Promise - .isAuthenticated() ⇒
boolean - .isSignedIn() ⇒
Promise.<boolean> - .listenUserSignIn(callback) ⇒
Promise.<void> - .getUserData() ⇒
UserData|null - .gapi
- .GoogleAuth
- .GoogleUser
- .LoginOptions
- .LoginResponse
- .UserData :
object
new GoogleAuthService()
Exposed as a $gapi global property accessible inside the application.
.getGapiClient() ⇒ Promise.<gapi>
Returns an initialized gapi client.
See: https://github.com/google/google-api-javascript-client/blob/master/docs/start.md
.getAuthInstance() ⇒ Promise.<GoogleAuth>
Returns the GoogleAuth object.
See: gapi.auth2.getAuthInstance
Since: 1.0.0
.getCurrentUser() ⇒ Promise.<GoogleUser>
Returns a GoogleUser object that represents the current user.
See: GoogleAuth.currentUser.get
Since: 1.0.0
.getOfflineAccessCode() ⇒ string | null
Returns the authorization code set via grantOfflineAccess.
.grantOfflineAccess() ⇒ Promise.<string>
Get permission from the user to access the specified scopes offline.
Returns: Promise.<string> - authorization code
See: GoogleAuth.grantOfflineAccess
.login([options]) ⇒ Promise.<LoginResponse>
Signs in the user and initializes session.
See: GoogleAuth.signIn
| Param | Type |
|---|---|
| [options] | LoginOptions |
.refreshToken() ⇒ Promise.<AuthResponse>
Forces a refresh of the access token.
This should be placed in your App.vue on the created page and run on a timer of 45min.
See: GoogleUser.reloadAuthResponse
Example
// NOTE: 45min refresh policy is what google recommends
window.setInterval(this.$gapi.refreshToken(), 2.7e+6)
.grant() ⇒ Promise.<GoogleUser>
Ask to grant scopes from user.
See: GoogleUser.grant
Since: 0.4.0
.logout() ⇒ Promise
Signs out the current account from the application and clear session storage.
See: GoogleAuth.signOut
.isAuthenticated() ⇒ boolean
Determines if the user is signed in via local storage.
.isSignedIn() ⇒ Promise.<boolean>
Determines if the user is signed in via Google.
See: GoogleUser.isSignedIn
Since: 0.0.10
.listenUserSignIn(callback) ⇒ Promise.<void>
Accept the callback to be notified when the authentication status changes.
See: GoogleAuth.isSignedIn.listen
Since: 0.0.10
| Param | Type | Description |
|---|---|---|
| callback | function | the callback function to be notified of an authentication status change |
.getUserData() ⇒ UserData | null
Gets the user data from local storage
.gapi
Google API Client.
See: https://github.com/google/google-api-javascript-client
.GoogleAuth
Singleton class that provides methods to allow the user to sign in with a Google account, get the user's current sign-in status, get specific data from the user's Google profile, request additional scopes, and sign out from the current account.
See: https://developers.google.com/identity/sign-in/web/reference#authentication
.GoogleUser
Object that represents the current user.
See: https://developers.google.com/identity/sign-in/web/reference#googleusergetid
.LoginOptions
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| [grantOfflineAccess] | boolean | false | Additionally gets permission from the user to access the specified scopes offline via getOfflineAccessCode |
.LoginResponse
Properties
| Name | Type | Description |
|---|---|---|
| currentUser | GoogleUser | Current user |
| gapi | gapi | Initialized gapi client |
| hasGrantedScopes | boolean | true if the requested scopes were granted. |
| [code] | string | Authorization code if grantOfflineAccess: true |
.UserData : object
See
Properties
| Name | Type | Description |
|---|---|---|
| id | string | user's unique ID string |
| firstName | string | given name |
| lastName | string | family name |
| fullName | string | full name |
string | ||
| imageUrl | string | |
| expiresAt | number | |
| accessToken | string | granted access token |
| idToken | string | granted ID token |
| [offlineAccessCode] | string |