@knowlearning/agents 0.6.1 → 0.6.3

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.
@@ -3,6 +3,7 @@ const AUTH_HOST = 'https://auth.knowlearning.systems'
3
3
  function login() {
4
4
  const provider = 'google'
5
5
  const state = Math.random().toString(36).substring(2)
6
+ localStorage.setItem('state', state)
6
7
 
7
8
  window.location.href = `${AUTH_HOST}/${provider}/${state}/${encodeURIComponent(window.location.href)}`
8
9
  }
@@ -134,8 +134,8 @@ export default function embed(environment, iframe) {
134
134
  listeners[event] = fn
135
135
  }
136
136
 
137
- function auth(token) {
138
- postMessage({ type: 'auth', token })
137
+ function auth(token, state) {
138
+ postMessage({ type: 'auth', token, state })
139
139
  }
140
140
 
141
141
  return {
@@ -32,10 +32,11 @@ export default function EmbeddedAgent() {
32
32
  }
33
33
 
34
34
  addEventListener('message', async ({ data }) => {
35
- console.log('embedded message', data)
36
35
  if (data.type === 'auth') {
37
36
  // TODO: switch to access_token
38
- localStorage.setItem('token', data.token)
37
+ if (localStorage.getItem('state') === data.state) {
38
+ localStorage.setItem('token', data.token)
39
+ }
39
40
  send({ type: 'close' })
40
41
  }
41
42
  else if (data.type === 'setup') resolveSession(data.session)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowlearning/agents",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "API for embedding applications in KnowLearning systems.",
5
5
  "main": "node.js",
6
6
  "browser": "browser.js",
@@ -24,6 +24,8 @@
24
24
  "homepage": "https://github.com/knowlearning/core#readme",
25
25
  "dependencies": {
26
26
  "fast-json-patch": "^3.1.1",
27
- "uuid": "^8.3.2"
27
+ "uuid": "^8.3.2",
28
+ "vue": "^3.3.4",
29
+ "vuex": "^4.1.0"
28
30
  }
29
31
  }