Merge pull request #669 from h3poteto/iss-665

refs #665 Save refresh token if it exists
This commit is contained in:
AkiraFukushima 2018-10-20 20:52:50 +09:00 committed by GitHub
commit 526f2b485a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 11 deletions

14
package-lock.json generated
View File

@ -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",

View File

@ -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",

View File

@ -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
}