From 1a8f2a702a35b17c059164feba3d39ec20abf8b4 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Sat, 20 Oct 2018 20:38:38 +0900
Subject: [PATCH] refs #665 Save refresh token if it exists
---
package-lock.json | 14 +++++++-------
package.json | 2 +-
src/main/auth.js | 9 ++++++---
3 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index e4546d220f..82b41d4467 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -210,7 +210,7 @@
},
"@types/events": {
"version": "1.2.0",
- "resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
+ "resolved": "http://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
"integrity": "sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA=="
},
"@types/form-data": {
@@ -227,9 +227,9 @@
"integrity": "sha512-87XkD9qDXm8fIax+5y7drx84cXsu34ZZqfB7Cial3Q/2lxSoJ/+DRaWckkCbxP41wFSIrrb939VhzaNxj4eY1w=="
},
"@types/oauth": {
- "version": "0.9.0",
- "resolved": "https://registry.npmjs.org/@types/oauth/-/oauth-0.9.0.tgz",
- "integrity": "sha512-1oouefxKPGiDkb5m6lNxDkFry3PItCOJ+tlNtEn/gRvWShb2Rb3y0pccOIGwN/AwHUpwsuwlRwSpg7aoCN3bQQ==",
+ "version": "0.9.1",
+ "resolved": "https://registry.npmjs.org/@types/oauth/-/oauth-0.9.1.tgz",
+ "integrity": "sha512-a1iY62/a3yhZ7qH7cNUsxoI3U/0Fe9+RnuFrpTKr+0WVOzbKlSLojShCKe20aOD1Sppv+i8Zlq0pLDuTJnwS4A==",
"requires": {
"@types/node": "*"
}
@@ -10723,9 +10723,9 @@
"dev": true
},
"megalodon": {
- "version": "0.4.3",
- "resolved": "https://registry.npmjs.org/megalodon/-/megalodon-0.4.3.tgz",
- "integrity": "sha512-9Te8YZiKZmfzv8paUzlKsPh23ChziCYnS9FGL/XWspT+EpEcxfJ2p6uM3CoZArhzDng/mykR6uxAXQ4rF7zRgA==",
+ "version": "0.4.4",
+ "resolved": "https://registry.npmjs.org/megalodon/-/megalodon-0.4.4.tgz",
+ "integrity": "sha512-uiUxwFaUupIkYGuUvUGqS0kLtC+8lQt685RoWKTD+locctqybzySG7VXWlCekZg+GwYtrroKV7iYj8sigre0pg==",
"requires": {
"@types/oauth": "^0.9.0",
"@types/request": "^2.47.0",
diff --git a/package.json b/package.json
index a961305239..4de00943df 100644
--- a/package.json
+++ b/package.json
@@ -110,7 +110,7 @@
"i18next-sync-fs-backend": "^1.1.0",
"is-empty": "^1.2.0",
"lodash": "^4.17.10",
- "megalodon": "0.4.3",
+ "megalodon": "0.4.4",
"moment": "^2.21.0",
"mousetrap": "^1.6.2",
"nedb": "^1.8.0",
diff --git a/src/main/auth.js b/src/main/auth.js
index b3d8c7dd9e..72afe74400 100644
--- a/src/main/auth.js
+++ b/src/main/auth.js
@@ -45,6 +45,7 @@ export default class Authentication {
clientId: this.clientId,
clientSecret: this.clientSecret,
accessToken: '',
+ refreshToken: '',
username: '',
accountId: '',
avatar: '',
@@ -55,7 +56,7 @@ export default class Authentication {
}
async getAccessToken (code) {
- const token = await Mastodon.fetchAccessToken(this.clientId, this.clientSecret, code, this.baseURL)
+ const tokenData = await Mastodon.fetchAccessToken(this.clientId, this.clientSecret, code, this.baseURL)
const search = {
baseURL: this.baseURL,
domain: this.domain,
@@ -63,13 +64,15 @@ export default class Authentication {
clientSecret: this.clientSecret
}
const rec = await this.db.searchAccount(search)
- const accessToken = token.access_token
+ const accessToken = tokenData.accessToken
+ const refreshToken = tokenData.refreshToken
const data = await this.db.fetchAccount(rec, accessToken)
await this.db.updateAccount(rec._id, {
username: data.username,
accountId: data.id,
avatar: data.avatar,
- accessToken: accessToken
+ accessToken: accessToken,
+ refreshToken: refreshToken
})
return accessToken
}