Advertisement
BrendanHart

Untitled

Feb 23rd, 2020
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {APIRouterWrapper} from './api';
  2. import * as express from 'express';
  3. import {IRouterWrapper} from "./Router.interface";
  4. import {AuthService} from "../services/auth-service";
  5.  
  6. export class BaseRouterWrapper implements IRouterWrapper {
  7.   private readonly expressRouter: express.Router;
  8.  
  9.   constructor(private apiRouter: APIRouterWrapper,
  10.               private authService: AuthService) {
  11.     this.expressRouter = express.Router();
  12.   }
  13.  
  14.   public setupRoutes(): void {
  15.     this.apiRouter.setupRoutes();
  16.     this.expressRouter.use('/api', this.apiRouter.getRouter());
  17.     this.expressRouter.use('/callback', async (req, res, next) => {
  18.       const state = JSON.parse(req.query.state);
  19.       const savedState = this.authService.getUserState(state.userId);
  20.       if (savedState.securityToken === state.securityToken) {
  21.         await this.authService.associateAuthKey(req.query.code, savedState);
  22.         res.render('oauth-callback-success', {
  23.           verificationCode: state.securityToken,
  24.           providerName: 'Graph',
  25.           layout: false
  26.         })
  27.       } else {
  28.         res.send("FAILED");
  29.       }
  30.     });
  31.   }
  32.  
  33.   public getRouter(): express.Router {
  34.     return this.expressRouter;
  35.   }
  36. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement