diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-01-06 12:09:57 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-01-06 12:09:57 +0900 |
| commit | fef3d3f300c80bf26b0c6a203db5782f76463151 (patch) | |
| tree | 4b590d2c11e2d1f031cc3fff9ef1c9c76741cdc6 /src/api/endpoints/auth | |
| parent | [BREAKING CHANGE] Improve security (diff) | |
| download | sharkey-fef3d3f300c80bf26b0c6a203db5782f76463151.tar.gz sharkey-fef3d3f300c80bf26b0c6a203db5782f76463151.tar.bz2 sharkey-fef3d3f300c80bf26b0c6a203db5782f76463151.zip | |
Refactor: Rename userkey --> access-token
Diffstat (limited to 'src/api/endpoints/auth')
| -rw-r--r-- | src/api/endpoints/auth/accept.js | 24 | ||||
| -rw-r--r-- | src/api/endpoints/auth/session/userkey.js | 8 |
2 files changed, 16 insertions, 16 deletions
diff --git a/src/api/endpoints/auth/accept.js b/src/api/endpoints/auth/accept.js index 9eb5d2e7e2..110a0897df 100644 --- a/src/api/endpoints/auth/accept.js +++ b/src/api/endpoints/auth/accept.js @@ -7,7 +7,7 @@ import rndstr from 'rndstr'; const crypto = require('crypto'); import App from '../../models/app'; import AuthSess from '../../models/auth-session'; -import Userkey from '../../models/userkey'; +import AccessToken from '../../models/access-token'; /** * Accept @@ -20,24 +20,24 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Get 'token' parameter - const token = params.token; - if (token == null) { + const sesstoken = params.token; + if (sesstoken == null) { return rej('token is required'); } // Fetch token const session = await AuthSess - .findOne({ token: token }); + .findOne({ token: sesstoken }); if (session === null) { return rej('session not found'); } - // Generate userkey - const key = rndstr('a-zA-Z0-9', 32); + // Generate access token + const token = rndstr('a-zA-Z0-9', 32); - // Fetch exist userkey - const exist = await Userkey.findOne({ + // Fetch exist access token + const exist = await AccessToken.findOne({ app_id: session.app_id, user_id: user._id, }); @@ -50,15 +50,15 @@ module.exports = (params, user) => // Generate Hash const sha512 = crypto.createHash('sha512'); - sha512.update(key + app.secret); + sha512.update(token + app.secret); const hash = sha512.digest('hex'); - // Insert userkey doc - await Userkey.insert({ + // Insert access token doc + await AccessToken.insert({ created_at: new Date(), app_id: session.app_id, user_id: user._id, - key: key, + token: token, hash: hash }); } diff --git a/src/api/endpoints/auth/session/userkey.js b/src/api/endpoints/auth/session/userkey.js index 2626e4ce39..f85a720ea4 100644 --- a/src/api/endpoints/auth/session/userkey.js +++ b/src/api/endpoints/auth/session/userkey.js @@ -5,7 +5,7 @@ */ import App from '../../../models/app'; import AuthSess from '../../../models/auth-session'; -import Userkey from '../../../models/userkey'; +import AccessToken from '../../../models/access-token'; import serialize from '../../../serializers/user'; /** @@ -53,8 +53,8 @@ module.exports = (params) => return rej('this session is not allowed yet'); } - // Lookup userkey - const userkey = await Userkey.findOne({ + // Lookup access token + const accessToken = await AccessToken.findOne({ app_id: app._id, user_id: session.user_id }); @@ -66,7 +66,7 @@ module.exports = (params) => // Response res({ - userkey: userkey.key, + access_token: accessToken.token, user: await serialize(session.user_id, null, { detail: true }) |