You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### (a) Handling Google sign-in, getting the one-time authorization code from Google
24
-
25
-
#### Frontend-side(Vue.js)
20
+
## Property
21
+
| Property | Description | Type |
22
+
|--------------|--------------------|----------|
23
+
| GoogleAuth | return of gapi.auth2.getAuthInstance() | Object |
24
+
| isAuthorized | Whether or not you have auth | Boolean |
25
+
| isInit | Whether or not api init | Boolean |
26
+
| isLoaded | Whether or not api init | Function |
27
+
| signIn | function for sign-in | Function |
28
+
| getAuthCode | function for getting authCode | Function |
29
+
| signOut | function for sign-out | Function |
30
+
31
+
## Usage - Getting authorization code
32
+
>The `authCode` that is being returned is the `one-time code` that you can send to your backend server, so that the server can exchange for its own access_token and refresh_token.
33
+
34
+
### Frontend-side(Vue.js)
26
35
```javascript
27
36
this.$gAuth.getAuthCode()
28
37
.then(authCode=> {
@@ -36,9 +45,9 @@ this.$gAuth.getAuthCode()
36
45
//on fail do something
37
46
})
38
47
```
39
-
The `authCode` that is being returned is the `one-time code` that you can send to your backend server, so that the server can exchange for its own access token and refresh token.
40
48
41
-
#### Backend-side(Golang)
49
+
50
+
### Backend-side(Golang)
42
51
```go
43
52
auth_code:= ac.Code//from front-end side
44
53
// generate a config of oauth
@@ -64,39 +73,21 @@ Note, ```RedirectURL``` must be ```postmessage```!!
64
73
65
74
66
75
67
-
### (b) Alternatively, if you would like to directly get back the access_token and id_token
76
+
##Usage - Directly get back the access_token and id_token or use api request
68
77
69
78
```javascript
70
79
this.$gAuth.signIn()
71
80
.then(GoogleUser=> {
72
-
//on success do something
73
-
console.log('GoogleUser', GoogleUser)
81
+
// On success do something, refer to https://developers.google.com/api-client-library/javascript/reference/referencedocs#googleusergetid
82
+
console.log('user', GoogleUser)
83
+
this.isSignIn=this.$gAuth.isAuthorized
74
84
})
75
85
.catch(error=> {
76
86
//on fail do something
77
87
})
78
88
```
79
89
80
-
The `googleUser` object that is being returned will be:
81
-
```javascript
82
-
{
83
-
"token_type":"Bearer",
84
-
"access_token":"xxx",
85
-
"scope":"xxx",
86
-
"login_hint":"xxx",
87
-
"expires_in":3600,
88
-
"id_token":"xxx",
89
-
"session_state": {
90
-
"extraQueryParams": {
91
-
"authuser":"0"
92
-
}
93
-
},
94
-
"first_issued_at":1234567891011,
95
-
"expires_at":1234567891011,
96
-
"idpId":"google"
97
-
}
98
-
```
99
-
refer to [google signIn reference : users](https://developers.google.com/identity/sign-in/web/reference#users)
90
+
refer to [google signIn reference : GoogleUser](https://developers.google.com/api-client-library/javascript/reference/referencedocs#googleusergetid)
0 commit comments