{"size": 1919, "ext": "js", "max_stars_repo_path": "api/security.js", "max_stars_repo_name": "SmartinfoLogiks/Boilerplate-nodejs-api", "max_stars_repo_stars_event_min_datetime": "2022-03-12T00:02:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-12T00:02:12.000Z", "max_issues_repo_path": "api/security.js", "max_issues_repo_name": "dikshita1997/demo", "max_issues_repo_issues_event_min_datetime": "2021-05-10T16:19:41.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-26T16:47:02.000Z", "max_forks_repo_path": "api/security.js", "max_forks_repo_name": "SmartinfoLogiks/Boilerplate-nodejs-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 7, "max_forks_count": null, "avg_line_length": 33.0862068966, "max_line_length": 134, "alphanum_fraction": 0.5341323606}
/*
 * All Security Logic is written here
 * 
 * */
module.exports = function(server) {

    server.use(function(req, res, next) {
        // return next(
        //     new errors.ForbiddenError("Public Key Invalid"),
        // );

        authkey = req.header("authkey");

        req.set("GUID", "TEST");

        //API Validator : FIND API Authentication Protocol for the GUID
        //Could be Bearer, OAuth2, 2FA, etc.
        mbeeAuth = req.header("authorization");

        //console.log("Security Authorization");

        return next();
    });


    // const rjwt = require('restify-jwt-community');

    // // using restify-jwt to lock down everything except /auth
    // server.use(rjwt(server.config.jwt).unless({
    //       path: server.config.noauth,
    //       method: 'OPTIONS'
    //   }));

    // server.use((req, res, next) => {
    //     if(req.method=="OPTIONS") {
    //       return next();
    //     }
    //     if(req.user==null) {
    //       if(server.config.noauth.indexOf(req._url.path)>=0) {
    //         //console.log("NoAuth Request Allowed",req._url.path);
    //       } else {
    //         console.log("NoAuth Request Denied",req._url.path);
    //         return next(new errs.UnauthorizedError("No Authorization Available"));
    //       }
    //     } else {
    //       pathParent = req._url.path.split("/")[1] + "/";
    //       req.user.scope.push("/auth/info");
    //       //console.log(pathParent,req._url.path,req.user.scope);
    //       if(req.user.scope.indexOf("*")>=0 || req.user.scope.indexOf(req._url.path)>=0 || req.user.scope.indexOf(pathParent)>=0) {
    //         console.log("New Authorized Request Allowed");
    //       } else {
    //         console.log("Auth Request Denied Due to Scope");
    //         return next(new errs.UnauthorizedError("Out of Scope Error"));
    //       }
    //     }
    //     return next();
    // });
}