Checks if we're authenticated on the SAFE network
@returns {*}
8076
function () {
    this.log('Checking if authorized...');
    return this.Request.get('/auth').auth().execute()
      // let's use our own function here, that resolve true or false,
      // rather than throwing an error if invalid token
      .then(function () {
        this.log('Authorized');
        return true;
      }.bind(this), function (response) {
        this.log('Not authorized, or received error.', response);
        if (response.status === 401) {
          // Remove any auth from storage and Request class
          this.log('Not authorized, removing any stored auth data.');
          clearAuthData.call(this);

          // Return false
          return false;
        } else {
          // Any other status is another error, throw the response
          throw response;
        }
      }.bind(this));
  }
582305
function isSecure(url) {
    if (typeof url !== 'string') {
      return false;
    }
    var parts = url.split('://');
    if (parts[0] === 'https') {
      return true;
    }
    return false;
  }
107309
def should_require_authentication(self, url):
        
        return (not self.routes # require auth for all URLs
                or any(route.match(url) for route in self.routes))
51918
public function isAuthenticated()
    {
        $client = parent::getHttpClient();
        if ($client->getClientLoginToken() ||
            $client->getAuthSubToken()
        ) {
            return true;
        }

        return false;
    }
352243
function trustableAuthHandler(//{{{
    authHandler,
    pathSpec,
    ext,
    method,
    ac,
    req,
    actualRes,
    actualNext
) {

    // Provide fake http environment:
    var httpDone = false;
    var res = Object.create(actualRes);
    res.send = function newSend(){
        actualRes.send.apply(actualRes, arguments);
        httpDone = true;
    };
    function next(){
        actualNext.apply(this, arguments);
        httpDone = true;
    };

    // Call actual authentication handler:
    var auth = authHandler(
        pathSpec,
        ext,
        method,
        ac,
        req,
        res,
        next
    );

    // Ensure http handshake is fully handled:
    if (! httpDone && typeof auth != "object") {
        var msg = (typeof auth == "string")
            ? auth
            : "Access denied."
        ;
        Util.sendStatusMessage(actualRes, "forbidden", msg);
        httpDone = true;
    };
    if (httpDone) auth = false; // Any response handling in authHandler is also an access reject.


    // Ensure consistent auth interface.
    if (auth) {
        auth.filter || (auth.filter = defaultResponse.filter);
        auth.userData || (auth.userData = defaultResponse.userData);
        auth.privileges || (auth.privileges = defaultResponse.privileges);
        if (
            (typeof auth.filter != "function")
            || (typeof auth.userData != "object")
            || (typeof auth.privileges != "function")
        ) {
            console.error("Wrong auth object", auth);
            Util.sendStatusMessage(actualRes, "error", "Internal Server Error");
                // With httpDone = true we were never got here ;-)
        };
    };

    // Return trusted auth data.
    return auth;

}
730105
function authenticateUser (req, res, next) {
  // Check for verified access token
  if (req.claims && req.claims.sub) {
    User.get(req.claims.sub, function (err, user) {
      if (err) {
        return next(err)
      }

      if (!user) {
        return next(new UnauthorizedError({
          realm: 'user',
          error: 'unknown_user',
          error_description: 'Unknown user',
          statusCode: 401
        }))
      }

      req.user = user
      next()
    })

  // User is not authenticated.
  } else if (!req.user) {
    next(new UnauthorizedError({
      statusCode: 401
    }))

  // User is authenticated.
  } else {
    next()
  }
}
1212074
public boolean isUnauthenticated(Subject subject) {
        if (subject == null) {
            return true;
        }

        WSCredential wsCred = getWSCredential(subject);
        if (wsCred == null) {
            return true;
        } else {
            return wsCred.isUnauthenticated();
        }
    }
488669
public int checkSecurity()
    {
        int iLevel = Constants.LOGIN_USER;
        try {
            iLevel = Integer.parseInt(this.getProperty(Params.SECURITY_LEVEL));
        } catch (NumberFormatException ex) {
        }
        
        int iAccessAllowed = DBConstants.NORMAL_RETURN;
        
        if (iLevel == Constants.LOGIN_USER)
            if (!DBConstants.ANON_USER_ID.equalsIgnoreCase(this.getProperty(DBParams.USER_ID)))
        {
            if (this.getProperty(DBParams.USER_NAME) != null)
                iAccessAllowed = DBConstants.AUTHENTICATION_REQUIRED;   // If you have an account, you need to sign into it.
        }
        
        return iAccessAllowed;
    }
158843
function isAuthenticated() {
  var storageEngine = App.pkg.settings.storage_engine || 'localStorage';
  var name = App.pkg._id;
  var auth = window[App.pkg.settings.auth_module];
  if (window[storageEngine][name + '-session']) {
    var data = JSON.parse(window[storageEngine][name + '-session']);
    data['empty'] = false;
    window.user = new auth.models.User(data);
  } else {
    window.user = new auth.models.User();
  }
  return !window.user.get('empty');
}
45823
public function is_authenticated() {
		$retval = false;
		$parentRes = false;
		
		try {
			if(parent::is_authenticated()) {
				$parentRes = true;
				$retval = $this->is_valid_sid($this->sid);
			}
		}
		catch(Exception $e) {
			$this->exception_handler($e->getMessage());
		}
		
		return ($retval);
	}
1174129
async function protect (ctx, next) {
	if (ctx.isAuthenticated()) {
		await next();
	} else {
		await passport.authenticate('bearer', {
			session: false
		}, async function (err, user) {
			// console.log(err, user);
			/* istanbul ignore if */
			if (err) {
				throw err;
			}
			if (user === false) {
				ctx.body = null;
				ctx.status = 401;
			} else {
				ctx.state.user = user;
				await next();
			}
		})(ctx);
	}
}
577662
function verifyToken(token) {
    var decodedToken = jwt.decode(token)
    return userdb.users.filter(user => user.name == decodedToken).length > 0;
}
532666
public function isAuthenticated()
    {
        if(!array_key_exists(self::AUTHENTICATED, $this->_map))
            return false;

        $authc      = $this->_map[self::AUTHENTICATED];
        $authStatus = ($authc != null && $authc);
        return $authStatus;
    }
630456
public function isAuthenticated()
    {
        $authenticated = false;

        if (is_null($this->parameters)) {
            return $authenticated;
        }

        $calculatedHash = md5(
            $this->parameters['item'] . '|' .
            $this->parameters['page'] . '|' .
            $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']
        );

        if ($this->parameters['hash'] === $calculatedHash) {
            $authenticated = true;
        }

        return $authenticated;
    }
167845
function checkInternetConnection () {
  return new Promise((resolve) => {
    require('dns').lookup('microsoft.com', (err) => {
      if (err && err.code === 'ENOTFOUND') {
        resolve(false)
      } else {
        resolve(true)
      }
    })
  })
}
746930
function isLoggedInMiddleware() {
		return function isLoggedIn(req, res, next) {
			const AclUser = mongoose.model("TransomAclUser");

			if ((req.headers && req.headers.authorization) || (req.body && req.body.access_token) || (req.query && req.query.access_token)) {
				// Verify the authorization token or fail.
				passport.authenticate('bearer', {
					session: false
				}, function (err, user, info) {
					if (err) {
						return next(err);
					}
					if (!user || (info && info.indexOf("invalid_token") >= 0)) {
						// Something didn't work out.  Token Expired / Denied.
						debug("NOT LoggedIn - Invalid");
						return next(new restifyErrors.InvalidCredentialsError("Incorrect or expired credentials"));
					} else {
						// Properly authenticated!
						return next();
					}
				})(req, res, next);
			} else {
				// debug("No Authorization header or query access_token. Trying Anonymous.");
				if (localuser.anonymous !== false) {
					// Attempt anonymous login, if possible;
					AclUser.findOne({
						'username': 'anonymous',
						'active': true
					}, function (err, user) {
						if (err) {
							return next(err);
						}
						if (user) {
							req.locals = req.locals || {};
							req.locals.user = user;
							return next();
						}
						// Oh no, not authenticated
						debug("No bearer token provided or query access_token. No Anonymous user available.");
						return next(new restifyErrors.InvalidCredentialsError("No bearer token provided or query access_token. No Anonymous user available."));
					});
				} else {
					debug("No bearer token provided or query access_token.");
					return next(new restifyErrors.InvalidCredentialsError("No bearer token provided or query access_token."));
				}
			}
		}
	}
1050281
function _isValidNodeURI(nodeURI) {
  if (!_isString(nodeURI)) return false

  try {
    let isValidURI = isURL(nodeURI, {
      protocols: ['http', 'https'],
      require_protocol: true,
      host_blacklist: ['0.0.0.0']
    })

    let parsedURI = url.parse(nodeURI).hostname

    // Valid URI w/ IPv4 address?
    return isValidURI && isIP(parsedURI, 4)
  } catch (error) {
    return false
  }
}