@live-change/google-authentication-service 0.8.34 → 0.8.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/googleClient.js CHANGED
@@ -33,7 +33,8 @@ export async function getTokensWithCode(code, redirectUri) {
33
33
  const response = await axios(options)
34
34
  return response.data
35
35
  } catch(error) {
36
- console.error("OAUTH ERROR", error)
36
+ console.error("OAUTH ERROR", error?.stack || error?.message || JSON.stringify(error))
37
+ console.error("OAUTH ERROR RESPONSE", error?.response?.data)
37
38
  throw error?.response?.data ? new Error(error?.response?.data) : error
38
39
  }
39
40
  }
package/offlineAccess.js CHANGED
@@ -2,22 +2,33 @@ import App from '@live-change/framework'
2
2
  const app = App.app()
3
3
  import definition from './definition.js'
4
4
  import Debug from 'debug'
5
+ import { getTokensWithCode, getUserInfo } from './googleClient.js'
5
6
  const debug = Debug('services:googleAuthentication')
6
7
 
7
8
  export const OfflineAccess = definition.model({
8
9
  name: "OfflineAccess",
9
- userItem: {
10
+ userProperty: {
10
11
  userReadAccess: () => true
11
12
  },
12
13
  properties: {
13
- scope: {
14
- type: String,
14
+ scopes: {
15
+ type: Array,
16
+ of: {
17
+ type: String,
18
+ validation: ['nonEmpty']
19
+ },
15
20
  validation: ['nonEmpty']
16
21
  },
17
22
  refreshToken: {
18
23
  type: String,
19
24
  validation: ['nonEmpty']
20
25
  },
26
+ accessToken: {
27
+ type: String
28
+ },
29
+ accessTokenExpire: {
30
+ type: Date
31
+ },
21
32
  lastUse: {
22
33
  type: Date
23
34
  },
@@ -85,3 +96,38 @@ definition.event({
85
96
  }
86
97
  })
87
98
 
99
+ definition.action({
100
+ name: 'addOfflineAccessToken',
101
+ properties: {
102
+ code: {
103
+ type: String,
104
+ validation: ['nonEmpty']
105
+ },
106
+ redirectUri: {
107
+ type: String,
108
+ validation: ['nonEmpty']
109
+ },
110
+ scope: {
111
+ type: String,
112
+ validation: ['nonEmpty']
113
+ }
114
+ },
115
+ async execute({ code, redirectUri, scope }, { client, service }, emit) {
116
+ const user = client.user
117
+ if(!user) throw 'notAuthorized'
118
+ const tokens = await getTokensWithCode(code, redirectUri)
119
+ console.log("TOKENS", tokens)
120
+ const scopes = tokens.scope.split(' ')
121
+ if(tokens.token_type !== 'Bearer') throw new Error("Invalid token type "+tokens.token_type)
122
+ await service.triggerService({ type: 'googleAuthentication_setUserOwnedOfflineAccess', service: definition.name }, {
123
+ user, scopes,
124
+ accessToken: tokens.access_token,
125
+ accessTokenExpire: tokens.expires_in ? new Date(Date.now() + tokens.expires_in * 1000) : null,
126
+ refreshToken: tokens.refresh_token,
127
+ })
128
+
129
+ return {
130
+ action: 'addOfflineAccessToken'
131
+ }
132
+ }
133
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/google-authentication-service",
3
- "version": "0.8.34",
3
+ "version": "0.8.35",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,10 +21,10 @@
21
21
  "url": "https://www.viamage.com/"
22
22
  },
23
23
  "dependencies": {
24
- "@live-change/framework": "^0.8.34",
25
- "@live-change/relations-plugin": "^0.8.34",
24
+ "@live-change/framework": "^0.8.35",
25
+ "@live-change/relations-plugin": "^0.8.35",
26
26
  "google-auth-library": "9.0.0"
27
27
  },
28
- "gitHead": "40e61928bf43b35352c76fc135f36a2d8bd76c4a",
28
+ "gitHead": "90fbb746dc7270895daf17b437ca48c0b0a01c01",
29
29
  "type": "module"
30
30
  }