Merge branch 'master' of github.com:syuilo/misskey into swagger
This commit is contained in:
commit
0420fee5d2
26 changed files with 147 additions and 193 deletions
|
|
@ -4,8 +4,10 @@
|
|||
* Module dependencies
|
||||
*/
|
||||
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';
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
|
|
@ -41,35 +43,46 @@ 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,
|
||||
});
|
||||
|
||||
if (exist === null) {
|
||||
// Insert userkey doc
|
||||
await Userkey.insert({
|
||||
// Lookup app
|
||||
const app = await App.findOne({
|
||||
app_id: session.app_id
|
||||
});
|
||||
|
||||
// Generate Hash
|
||||
const sha512 = crypto.createHash('sha512');
|
||||
sha512.update(token + app.secret);
|
||||
const hash = sha512.digest('hex');
|
||||
|
||||
// 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
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue