How to add Bearer Token authentication in Postman ? - GeeksforGeeks (2024)

Skip to content

How to add Bearer Token authentication in Postman ? - GeeksforGeeks (1)

Last Updated : 05 Aug, 2024

Suggest changes

Like Article

Like

Save

Report

Postman is a crucial platform for developers, aiding in API testing, creation, and modification. APIs support various website features, such as user registration and login. For secure actions like changing passwords, Bearer Token Authentication is used. Upon login, the server issues a token, acting as proof of authentication. To access protected features, users send this token with their requests, validating their logged-in status through Bearer Token Authentication.

We will discuss two ways to add Bearer token in Postman:

Table of Content

  • In Authorization Section:
  • In Header Section:

What is Bearer Token authentication?

  • Bearer token authentication is used to verify login in services requiring authentication, generating a cryptographic string on the server for users.
  • Postman is used to test APIs, including those for real-world authentication, using Bearer Token Authentication.
  • To test a password change API, log in using the API designed for login, which returns a token proving the user’s authentication.

Now after login, we need to change the password. Now for changing password, we designed our API such that it takes a new password and changes the the previous password with the new password.
But we need to prove that we are already logged In. So for that, we will send Bearer Token with the request of changing password and we will send that token as a Bearer Token which we got on login .

In Authorization Section:

Steps to be followed to send bearer token along with new password-

  • Go to the Authorization Section
  • Find the dropdown in front of the type
  • In that dropdown select Bearer Token
  • Paste the Bearer token in the box on the right side
  • Now send the request after writing the password in the “raw” section

Output:

In Header Section:

Bearer Token is sent from front end in the header of the request. In the request, we put Bearer Token as a key-value pair, where “Authorization” will be the key and the “Bearer” Keyword followed by Bearer Token after a space as value.

Steps to be followed to send bearer token along with new password-

  • Go to Header Section
  • Check a key-value pair box to include that key-value pair
  • Put “Authorization” in the key
  • In value write “Bearer” then give a space
  • After giving space paste your Bearer Token
  • Now send the request after writing the password in the “raw” section

Output:

Conclusion:

Hence the purpose of Bearer Token authentication in Postman is to verify legitmitacy of the request. It helps in reducing the risk of unauthorized access and dangerous security breaches. It also increase developers efficiency during the development and testing phase because bearer token authentication works in the same way as the authentication in real world application works.



How to add Bearer Token authentication in Postman ? - GeeksforGeeks (3)

GeeksforGeeks

How to add Bearer Token authentication in Postman ? - GeeksforGeeks (4)

Improve

Please Login to comment...

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy

How to add Bearer Token authentication in Postman ? - GeeksforGeeks (5)

'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id, check: true }), success:function(result) { jQuery.ajax({ url: writeApiUrl + 'suggestions/auth/' + `${post_id}/`, type: "GET", dataType: 'json', xhrFields: { withCredentials: true }, success: function (result) { $('.spinner-loading-overlay:eq(0)').remove(); var commentArray = result; if(commentArray === null || commentArray.length === 0) { // when no reason is availaible then user will redirected directly make the improvment. // call to api create-improvement-post $('body').append('

'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id, }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.unlocked-status--improve-modal-content').css("display","none"); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); return; } var improvement_reason_html = ""; for(var comment of commentArray) { // loop creating improvement reason list markup var comment_id = comment['id']; var comment_text = comment['suggestion']; improvement_reason_html += `

${comment_text}

`; } $('.improvement-reasons_wrapper').html(improvement_reason_html); $('.improvement-bottom-btn').html("Create Improvement"); $('.improve-modal--improvement').hide(); $('.improvement-reason-modal').show(); }, error: function(e){ $('.spinner-loading-overlay:eq(0)').remove(); // stop loader when ajax failed; }, }); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); } else { if(loginData && !loginData.isLoggedIn) { $('.improve-modal--overlay').hide(); if ($('.header-main__wrapper').find('.header-main__signup.login-modal-btn').length) { $('.header-main__wrapper').find('.header-main__signup.login-modal-btn').click(); } return; } } }); $('.left-arrow-icon_wrapper').on('click',function(){ if($('.improve-modal--suggestion').is(":visible")) $('.improve-modal--suggestion').hide(); else{ $('.improvement-reason-modal').hide(); } $('.improve-modal--improvement').show(); }); function loadScript(src, callback) { var script = document.createElement('script'); script.src = src; script.onload = callback; document.head.appendChild(script); } function suggestionCall() { var suggest_val = $.trim($("#suggestion-section-textarea").val()); var array_String= suggest_val.split(" ") var gCaptchaToken = $("#g-recaptcha-response-suggestion-form").val(); var error_msg = false; if(suggest_val != "" && array_String.length >=4){ if(suggest_val.length <= 2000){ var payload = { "gfg_post_id" : `${post_id}`, "suggestion" : `

${suggest_val}

`, } if(!loginData || !loginData.isLoggedIn) // User is not logged in payload["g-recaptcha-token"] = gCaptchaToken jQuery.ajax({ type:'post', url: "https://apiwrite.geeksforgeeks.org/suggestions/auth/create/", xhrFields: { withCredentials: true }, crossDomain: true, contentType:'application/json', data: JSON.stringify(payload), success:function(data) { jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-section-textarea').val(""); jQuery('.suggest-bottom-btn').css("display","none"); // Update the modal content const modalSection = document.querySelector('.suggestion-modal-section'); modalSection.innerHTML = `

Thank You!

Your suggestions are valuable to us.

You can now also contribute to the GeeksforGeeks community by creating improvement and help your fellow geeks.

`; }, error:function(data) { jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Something went wrong."); jQuery('#suggestion-modal-alert').show(); error_msg = true; } }); } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Minimum 5 Words and Maximum Character limit is 2000."); jQuery('#suggestion-modal-alert').show(); jQuery('#suggestion-section-textarea').focus(); error_msg = true; } } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Enter atleast four words !"); jQuery('#suggestion-modal-alert').show(); jQuery('#suggestion-section-textarea').focus(); error_msg = true; } if(error_msg){ setTimeout(() => { jQuery('#suggestion-section-textarea').focus(); jQuery('#suggestion-modal-alert').hide(); }, 3000); } } document.querySelector('.suggest-bottom-btn').addEventListener('click', function(){ jQuery('body').append('

'); jQuery('.spinner-loading-overlay').show(); if(loginData && loginData.isLoggedIn) { suggestionCall(); return; } // load the captcha script and set the token loadScript('https://www.google.com/recaptcha/api.js?render=6LdMFNUZAAAAAIuRtzg0piOT-qXCbDF-iQiUi9KY',[], function() { setGoogleRecaptcha(); }); }); $('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked $('body').append('

'); $('.spinner-loading-overlay').show(); // send this option via create-improvement-post api jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.improvement-reason-modal').hide(); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); });

How to add Bearer Token authentication in Postman ? - GeeksforGeeks (2024)
Top Articles
Bulletproof Glass, Materials, Options Pros and Cons
How Much Can You Sell Your Business For - Guide To Business Value – Raincatcher
Craigslist Niles Ohio
Fusion
Hay day: Top 6 tips, tricks, and cheats to save cash and grow your farm fast!
Heska Ulite
Snowflake Activity Congruent Triangles Answers
Camstreams Download
Kinkos Whittier
Cyndaquil Gen 4 Learnset
Libinick
Scout Shop Massapequa
We Discovered the Best Snow Cone Makers for Carnival-Worthy Desserts
Chaos Space Marines Codex 9Th Edition Pdf
Target Minute Clinic Hours
Elbert County Swap Shop
Preggophili
EVO Entertainment | Cinema. Bowling. Games.
Jurassic World Exhibition Discount Code
Jazz Total Detox Reviews 2022
Schooology Fcps
Craigslist Sf Garage Sales
Dtlr On 87Th Cottage Grove
Broken Gphone X Tarkov
Tmj4 Weather Milwaukee
Unm Hsc Zoom
Gideon Nicole Riddley Read Online Free
Kagtwt
Vanessa West Tripod Jeffrey Dahmer
Games R Us Dallas
Petsmart Northridge Photos
Muziq Najm
Bbc Gahuzamiryango Live
Lyca Shop Near Me
Evil Dead Rise (2023) | Film, Trailer, Kritik
Mvnt Merchant Services
Rs3 Bis Perks
Entry of the Globbots - 20th Century Electro​-​Synthesis, Avant Garde & Experimental Music 02;31,​07 - Volume II, by Various
sacramento for sale by owner "boats" - craigslist
Garland County Mugshots Today
Ehome America Coupon Code
Login
✨ Flysheet for Alpha Wall Tent, Guy Ropes, D-Ring, Metal Runner & Stakes Included for Hunting, Family Camping & Outdoor Activities (12'x14', PE) — 🛍️ The Retail Market
Kjccc Sports
Sc Pick 3 Past 30 Days Midday
60 Days From August 16
Spn 3464 Engine Throttle Actuator 1 Control Command
Strange World Showtimes Near Century Federal Way
Latest Posts
Article information

Author: Mr. See Jast

Last Updated:

Views: 5756

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Mr. See Jast

Birthday: 1999-07-30

Address: 8409 Megan Mountain, New Mathew, MT 44997-8193

Phone: +5023589614038

Job: Chief Executive

Hobby: Leather crafting, Flag Football, Candle making, Flying, Poi, Gunsmithing, Swimming

Introduction: My name is Mr. See Jast, I am a open, jolly, gorgeous, courageous, inexpensive, friendly, homely person who loves writing and wants to share my knowledge and understanding with you.