summaryrefslogtreecommitdiff
path: root/src/api/endpoints/auth/accept.js
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-03-03 19:39:41 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-03-03 19:39:41 +0900
commitd1557bcae8abc45ea655d2fe0cdb6732a0207aa0 (patch)
tree56bb4b981df8d00c3d684352f3ee5b5057ee2a7e /src/api/endpoints/auth/accept.js
parentwip (diff)
downloadmisskey-d1557bcae8abc45ea655d2fe0cdb6732a0207aa0.tar.gz
misskey-d1557bcae8abc45ea655d2fe0cdb6732a0207aa0.tar.bz2
misskey-d1557bcae8abc45ea655d2fe0cdb6732a0207aa0.zip
wip
Diffstat (limited to 'src/api/endpoints/auth/accept.js')
-rw-r--r--src/api/endpoints/auth/accept.js98
1 files changed, 0 insertions, 98 deletions
diff --git a/src/api/endpoints/auth/accept.js b/src/api/endpoints/auth/accept.js
deleted file mode 100644
index 1c0b100948..0000000000
--- a/src/api/endpoints/auth/accept.js
+++ /dev/null
@@ -1,98 +0,0 @@
-'use strict';
-
-/**
- * Module dependencies
- */
-import rndstr from 'rndstr';
-const crypto = require('crypto');
-import App from '../../models/app';
-import AuthSess from '../../models/auth-session';
-import AccessToken from '../../models/access-token';
-
-/**
- * @swagger
- * /auth/accept:
- * post:
- * summary: Accept a session
- * parameters:
- * - $ref: "#/parameters/NativeToken"
- * -
- * name: token
- * description: Session Token
- * in: formData
- * required: true
- * type: string
- * responses:
- * 204:
- * description: OK
- *
- * default:
- * description: Failed
- * schema:
- * $ref: "#/definitions/Error"
- */
-
-/**
- * Accept
- *
- * @param {any} params
- * @param {any} user
- * @return {Promise<any>}
- */
-module.exports = (params, user) =>
- new Promise(async (res, rej) =>
-{
- // Get 'token' parameter
- const sesstoken = params.token;
- if (sesstoken == null) {
- return rej('token is required');
- }
-
- // Fetch token
- const session = await AuthSess
- .findOne({ token: sesstoken });
-
- if (session === null) {
- return rej('session not found');
- }
-
- // Generate access token
- const token = rndstr('a-zA-Z0-9', 32);
-
- // Fetch exist access token
- const exist = await AccessToken.findOne({
- app_id: session.app_id,
- user_id: user._id,
- });
-
- if (exist === null) {
- // Lookup app
- const app = await App.findOne({
- _id: session.app_id
- });
-
- // Generate Hash
- const sha256 = crypto.createHash('sha256');
- sha256.update(token + app.secret);
- const hash = sha256.digest('hex');
-
- // Insert access token doc
- await AccessToken.insert({
- created_at: new Date(),
- app_id: session.app_id,
- user_id: user._id,
- token: token,
- hash: hash
- });
- }
-
- // Update session
- await AuthSess.update(session._id, {
- $set: {
- user_id: user._id
- }
- });
-
- // Response
- res();
-});