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
Rossen Reports: Best credit cards with no foreign transaction fees
Renovation pros & cons
How To Fix Epson Printer Error Code 0x9e
Somboun Asian Market
Patreon, reimagined — a better future for creators and fans
Plaza Nails Clifton
Mopaga Game
Driving Directions To Fedex
Chris wragge hi-res stock photography and images - Alamy
Brgeneral Patient Portal
Recent Obituaries Patriot Ledger
Fototour verlassener Fliegerhorst Schönwald [Lost Place Brandenburg]
Lesson 3 Homework Practice Measures Of Variation Answer Key
Hover Racer Drive Watchdocumentaries
Goldsboro Daily News Obituaries
Skylar Vox Bra Size
5808 W 110Th St Overland Park Ks 66211 Directions
O'reilly's Auto Parts Closest To My Location
Lax Arrivals Volaris
Brett Cooper Wikifeet
Christina Steele And Nathaniel Hadley Novel
U Of Arizona Phonebook
College Basketball Picks: NCAAB Picks Against The Spread | Pickswise
SN100C, An Australia Trademark of Nihon Superior Co., Ltd.. Application Number: 2480607 :: Trademark Elite Trademarks
Gotcha Rva 2022
Apparent assassination attempt | Suspect never had Trump in sight, did not get off shot: Officials
Gen 50 Kjv
Jail Roster Independence Ks
Tu Housing Portal
Southtown 101 Menu
WOODSTOCK CELEBRATES 50 YEARS WITH COMPREHENSIVE 38-CD DELUXE BOXED SET | Rhino
Frequently Asked Questions - Hy-Vee PERKS
Armor Crushing Weapon Crossword Clue
Current Time In Maryland
Storelink Afs
Unm Hsc Zoom
A Small Traveling Suitcase Figgerits
Chattanooga Booking Report
Rocketpult Infinite Fuel
Drabcoplex Fishing Lure
Muma Eric Rice San Mateo
Edict Of Force Poe
Viewfinder Mangabuddy
Ludvigsen Mortuary Fremont Nebraska
062203010
Sams Gas Price Sanford Fl
Parent Portal Pat Med
21 Alive Weather Team
Iupui Course Search
Big Brother 23: Wiki, Vote, Cast, Release Date, Contestants, Winner, Elimination
Food and Water Safety During Power Outages and Floods
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.