Developer's Tools - How To Generate Basic Authentication Token

This demo is about another tool that I worked out during an assignment while working with an integration scenario using web services supporting basic authentication.

The problem with basic authentication is that you have to keep username and password stored somewhere in order to generate the authentication token.

Since I was integrating the external web services with SharePoint, so I felt to delegate the token generation process to an external tool and consume the Authentication Token directly without keeping username and password to be stored in the code itself.

To run this demo, I have created a simple interface that takes username and password as input and generates the basic Authentication Token and displays it in the “Authentication Token” section.

1

Now, let’s discuss the code for this functionality.

Step 1 - registering the button click event by mapping a functionget Token”.

Step 2 - calling the “getBasicAuthenticationToken” function by passing the username and password.

Step 3 - preparing the format required to convert plain text into hash value in base-64 format.

Step 4 - calling JavaScript function btoa which will encode the plain text into “base-64 format, a required hash value to prepare Basic Authentication Token.

Basic is prefixed to the hash value to comply with Basic Authentication Token Standards

2

That is it for the code.

Now, when we click “Get Authentication Token” button, we will see the authentication token in the “Authentication Token” section.

3

This token can be used for any web service supporting basic authentication, and this strategy can be merged with other functionalities too in order to generate this token on the fly.

Hope you find it helpful.

Up Next
    Ebook Download
    View all
    Learn
    View all