• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JWT Authorization header

Community Beginner ,
Feb 19, 2023 Feb 19, 2023

Copy link to clipboard

Copied

Hello Community,

i need help with this problem.

 

I would like to use the : 

JWT Authorization header using the Bearer scheme. Example: "Authorization: Bearer {token}"

 

Someone can help me? I know, how can read an xml from a APi but without a header autentication. I need to know how can i pass trow the header this kind of token.

 

Thanks a lot

Views

644

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 20, 2023 Feb 20, 2023

Hi.

 

If you're using XMLHttpRequest, you could so something like this:

 

var xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function()
{
    if (this.readyState == 4 && this.status == 200)
		console.log("request complete");
};

xhttp.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem("jwtoken"));
xhttp.open("GET", "filename", true);
xhttp.send();

 

 

https://www.w3schools.com/xml/xml_http.asp

https://stackoverflow.com/questions/52685215/how-to-send-jwt-in-xmlhttprequest

...

Votes

Translate

Translate
Community Expert ,
Feb 20, 2023 Feb 20, 2023

Copy link to clipboard

Copied

Hi.

 

If you're using XMLHttpRequest, you could so something like this:

 

var xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function()
{
    if (this.readyState == 4 && this.status == 200)
		console.log("request complete");
};

xhttp.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem("jwtoken"));
xhttp.open("GET", "filename", true);
xhttp.send();

 

 

https://www.w3schools.com/xml/xml_http.asp

https://stackoverflow.com/questions/52685215/how-to-send-jwt-in-xmlhttprequest

 

Have you tried it?

 

Please let us know.

 

Regards,

JC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 20, 2023 Feb 20, 2023

Copy link to clipboard

Copied

Hello Joao, you already help me (i changed to a new account but in the past already asked and you answered) anyway thanks!

 i am trying to use something like this :

 

var reqCurrent = new XMLHttpRequest();
reqCurrent.open("GET", "URL", true);

reqCurrent.setRequestHeader('Authorization', 'Bearer ' + 'Token');
reqCurrent.addEventListener("load", currentLoader);
reqCurrent.send();

 

but i getting "CORS Policy error" , this is from server configuration or my fault?

Thanks a lot, 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 20, 2023 Feb 20, 2023

Copy link to clipboard

Copied

Awesome! Really good to know!

 

Have you tried something like this:

xhttp.setRequestHeader("Access-Control-Allow-Origin", "*");

 

If that doesn't work, then you probably have to configure the server.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 20, 2023 Feb 20, 2023

Copy link to clipboard

Copied

It doesn't work.... i think is something from server configuration...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 23, 2023 Feb 23, 2023

Copy link to clipboard

Copied

Hello again.

 

Sorry for the late reply.

Did you manage to solve the problem? If it's really a server issue, I don't think I'll be able to help you much. I'm a front-end guy.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 23, 2023 Feb 23, 2023

Copy link to clipboard

Copied

LATEST

no i can not solve.... so it's server side. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines