REST(Representational State of Transfer) Partner with someone and think about important factors you need to consider when implementing Authentication. Consider the two buckets below.
REST
Architectural Constraints or set of Guidelines
- Sessions not used and should be Stateless. *No information stored
- Uses HTTP protocol *Use of GET,POST, PUT, DELETE
-Access resources using URL and returns JSON, XML.
RESTFul
A service that implements the Constraints and Guidelines
Conforming to theses guidelines affords faster, lightweight, and increased scalablity
HoppScotch - Easy to use web-based interface
Postman - Browser extension, Desktop application
Curl - Quick testing commandline interface
Insomnia REST - Commercial SaaS product and Limited Free version
Example using Curl
curl https://api.chucknorris.io/jokes/random //Simple GET request curl -d "id=1&createdAt=2021-02-27T08:57:20.804Z&name=Chris&avatar=null" -X POST https://603a806df1d6aa0017a10c48.mockapi.io/users
http/https node.js core modules - A good resource can be found here
npm package axios - Good documentation new website at https://axios-http.com/
Example using axios
const axios = require('axios'); //npm install axios // Make a request for a user with a given ID axios.get('/user?ID=12345') .then(function (response) { // handle success console.log(response); }) .catch(function (error) { // handle error console.log(error); }) .then(function () { // always executed });
// Node.js program to demonstrate the
// response.setHeaders() Method
// Importing http module
var http = require('http');
// Setting up PORT
const PORT = process.env.PORT || 3000;
// Creating http Server
var httpServer = http.createServer(
function(request, response) {
// Setting up Headers
response.setHeader('Content-Type', 'text/html');
response.setHeader('Set-Cookie', ['type=ninja',
'language=javascript']);
// Checking and printing the headers
console.log("When Header is set a string:",
response.getHeader('Content-Type'));
console.log("When Header is set an Array:",
response.getHeader('Set-Cookie'));
// Getting the set Headers
const headers = response.getHeaders();
// Printing those headers
console.log(headers);
// Prints Output on the browser in response
response.writeHead(200,
{ 'Content-Type': 'text/plain' });
response.end('ok');
});
// Listening to http Server
httpServer.listen(PORT, () => {
console.log("Server is running at port 3000...");
});
Or you can use third-party npm packages that will help with configuration such as helmet.js
Headers to consider for security purposes
Why do you think this would be necessary? What does this header help mitigate as it relates to security?
Strict-Transport-Security: max-age=expire-time
Strict-Transport-Security: max-age=expire-time; includeSubDomains
Strict-Transport-Security: max-age=expire-time; preload
//Example
Strict-Transport-Security: max-age=31536000; includeSubDomains
Why do you think this would be necessary? What does this header help mitigate as it relates to security?
Expect-CT: max-age=360000, enforce, report-uri="https://s_reports.mplsrenters.com/report"
Why do you think this would be necessary? What does this header help mitigate as it relates to security?
X-Frame-Options: DENY //page cannot be displayed in a frame, regardless of the site attempting to do so
X-Frame-Options: SAMEORIGIN //page can only be displayed in a frame on the same origin as the page itself
//Via server
Referrer-Policy: no-referrer
Referrer-Policy: no-referrer-when-downgrade
Referrer-Policy: origin
Referrer-Policy: origin-when-cross-origin
Referrer-Policy: same-origin
Referrer-Policy: strict-origin
Referrer-Policy: strict-origin-when-cross-origin
Referrer-Policy: unsafe-url
//Can also be sent via HTML using the meta tag
This Http header has parameters that can restrict protocol access and refuse interaction with insecure protocols
(T/F) HSTS is a trust on first use mechanism? You must visit the site first so that the browser knows that subsequent interaction must use HTTPS.
This Http Header provides an efficient way of monitoring and auditing SSL certificates in nearly real time ?
Which of the Http headers below helps with preventing clickjacking?
Which of the following can a referrer policy not restrict?