diff options
Diffstat (limited to 'src/api/authenticate.ts')
| -rw-r--r-- | src/api/authenticate.ts | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/src/api/authenticate.ts b/src/api/authenticate.ts deleted file mode 100644 index 537c3d1e1f..0000000000 --- a/src/api/authenticate.ts +++ /dev/null @@ -1,69 +0,0 @@ -import * as express from 'express'; -import App from './models/app'; -import { default as User, IUser } from './models/user'; -import AccessToken from './models/access-token'; -import isNativeToken from './common/is-native-token'; - -export interface IAuthContext { - /** - * App which requested - */ - app: any; - - /** - * Authenticated user - */ - user: IUser; - - /** - * Whether requested with a User-Native Token - */ - isSecure: boolean; -} - -export default (req: express.Request) => new Promise<IAuthContext>(async (resolve, reject) => { - const token = req.body['i'] as string; - - if (token == null) { - return resolve({ - app: null, - user: null, - isSecure: false - }); - } - - if (isNativeToken(token)) { - const user: IUser = await User - .findOne({ 'account.token': token }); - - if (user === null) { - return reject('user not found'); - } - - return resolve({ - app: null, - user: user, - isSecure: true - }); - } else { - const accessToken = await AccessToken.findOne({ - hash: token.toLowerCase() - }); - - if (accessToken === null) { - return reject('invalid signature'); - } - - const app = await App - .findOne({ _id: accessToken.app_id }); - - const user = await User - .findOne({ _id: accessToken.user_id }); - - return resolve({ - app: app, - user: user, - isSecure: false - }); - } -}); |