Why does my JavaScript get a “No 'Access-Control-Allow-Origin' header is present on the requested resource” error when Postman does not?

I am trying to do authorization using&nbsp;<a href="http://en.wikipedia.org/wiki/JavaScript" target="_blank">JavaScript</a>&nbsp;by connecting to the&nbsp;<a href="http://en.wikipedia.org/wiki/Representational_state_transfer#RESTful_web_services" target="_blank">RESTful</a>&nbsp;<a href="http://en.wikipedia.org/wiki/Application_programming_interface" target="_blank">API</a>&nbsp;built in&nbsp;<a href="https://en.wikipedia.org/wiki/Flask_%28web_framework%29" target="_blank">Flask</a>. However, when I make the request, I get the following error:

I am trying to do authorization using JavaScript by connecting to the RESTful API built in Flask. However, when I make the request, I get the following error:

XMLHttpRequest cannot load http://myApiUrl/login. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

I know that the API or remote resource must set the header, but why did it work when I made the request via the Chrome extension Postman?

This is the request code:

$.ajax({
    type: "POST",
    dataType: 'text',
    url: api,
    username: 'user',
    password: 'pass',
    crossDomain : true,
    xhrFields: {
        withCredentials: true
    }
})
    .done(function( data ) {
        console.log("done");
    })
    .fail( function(xhr, textStatus, errorThrown) {
        alert(xhr.responseText);
        alert(textStatus);
    });



Postman Tutorial | Postman Crash Course for Beginners | Learn API Testing using Postman

A Postman tutorial walking you through the most important steps inside the Postman App. Begin writing API tests now!&nbsp;&nbsp;

A Postman tutorial walking you through the most important steps inside the Postman App. Begin writing API tests now!  


RESTful APIs are everywhere nowadays but at the same time they are getting more complex to get started with: different HTTP methods, headers, cookies, dealing with file uploads or authentication with api keys, tokens, OAuth and so much more.


But before you start investing time writing code to retrieve the data the API is offering, why not test the request first to make sure everything is working as expected?


This is where the Postman App comes in! Postman allows you very quickly create a request with the required HTTP method and parameters, submit the request and easily inspect the results. Postman can help if you are developing APIs as well! I have created this course for testing engineers and well as for software developers.


Postman can help you during the development of your API as well as after the API is completed, by running tests that make sure your API is still working as intended.


In this Postman crash course for beginners, we will start exploring the features of Postman, creating request and building simple workflows. Then we will continue by writing API tests and automatically running a Postman collection by using the Postman Collection Runner.



How to Install Postman in Linux

How to Install Postman in Linux

<img src="https://linux4one.com/wp-content/uploads/2019/04/How-to-Install-Postman-in-Linux.jpg">

How to Install Postman in Linux

Table of Contents

Install Postman in Linux

Postman is one of the useful tool built for API development. Using Postman you can develop API faster. In the beginning, Postman provided as an extension of Google Chrome browser but later it is developed as an independent tool as very much growth in its popularity. Today Postman is available for all major operating systems such as Linux, Windows, and MacOS. In this tutorial, you are going to learn How to install Postman in Linux.

Prerequisites

Before you start installing Postman in Linux. You must have a non-root user account on your server with sudo privileges.

Install Postman in Linux

Installing Postman on Linux is one of the easiest things today. We are going to install Postman on Ubuntu using snappy package system tool.

Download Postman by running following command in your Linux system:

wget https://dl.pstmn.io/download/latest/linux64 -O postman-linux-x64.tar.gz

Extract the downloaded file by running the following command in /opt directory:

sudo tar -xvzf postman-linux-x64.tar.gz -C /opt

Finally, create a symbolic link running following command in terminal:

sudo ln -s /opt/Postman/Postman /usr/bin/postman

After completing the above process you have successfully installed Postman on your Linux system.

Now to create a desktop icon you can run below command:

cat << EOF > ~/.local/share/applications/postman2.desktop
[Desktop Entry]
Name=Postman
GenericName=API Client
X-GNOME-FullName=Postman API Client
Comment=Make and view REST API calls and responses
Keywords=api;
Exec=/opt/Postman/Postman
Terminal=false
Type=Application
Icon=/opt/Postman/app/resources/app/assets/icon.png
Categories=Development;Utilities;
EOF

Now you have successfully completed installtion of Postman in your Linux system.

Using Postman

To start using Postman, go to Applications -> Postman and launch Postman in Linux or you can simply run following command.

postman

On the first launch, you will see the following window for Sign Up using Email or Google Account. Otherwise, you can also Sign In if you have an existing account.

how to install Postman – Create Account or Sign In

After signing in or creating the new account you are ready to start using Postman for API development.

Following is an example in which we sending a GET request to the URL.

How to install Postman – Start Using Postman

Conclusion

In this tutorial, you have learned how to install Postman in Linux successfully. If you have any of the queries regarding this then you can comment below.

Originally published on https://linux4one.com



Sending JWT token in the headers with Postman

I'm testing an implementation of JWT Token based security based off the following&nbsp;<a href="https://auth0.com/blog/2014/01/07/angularjs-authentication-with-cookies-vs-token/" target="_blank">article</a>. I have successfully received a token from the test server. I can't figure out how to have the Chrome POSTMAN REST Client program send the token in the header.

I'm testing an implementation of JWT Token based security based off the following article. I have successfully received a token from the test server. I can't figure out how to have the Chrome POSTMAN REST Client program send the token in the header.


My questions are as follows:

1) Am I using the right header name and/or POSTMAN interface?

2) Do I need to base 64 encode the token? I thought I could just send the token bac