How to set Authorization token in request headers when user attempts to login on discourse

Hello all,

I am working on integrating my freshly built discourse community with my website. I have also implemented SSO (DiscourseConnect). Everything works fine on Postman.

The problem is I am stuck integrating those.

I can perform authentication in Postman by passing the authentication token in request headers. But I am unable to figure out how to pass the Authentication token in request headers when the user attempts to log in via my discourse website.

In other words, how do I set the Authorization token (present in the browser’s localStorage) in the request headers of the URL that is being sent to my backend?

My tech stack:- React, Django-rest

For a better understanding please take a look at the following:-

Response:-
http://discuss.example.com/session/sso_login?sso=bm9uY2U9Y2I2ODI1MWVlZmI1MjExZTU4YzAwZmYxMzk1ZjBjMGImbmFtZT1zYW0mdXNlcm5hbWU9c2Ftc2FtJmVtYWlsPXRlc3QlNDB0ZXN0LmNvbSZleHRlcm5hbF9pZD1oZWxsbzEyMyZyZXF1aXJlX2FjdGl2YXRpb249dHJ1ZQ%3D%3D&sig=3d7e5ac755a87ae3ccf90272644ed2207984db03cf020377c8b92ff51be3abc3

In the above request, I am explicitly setting the Authorization token to the request headers.

While integrating, how can I set the token (present in the browser’s localStorage) to request headers while redirecting the request to my backend?

I’m a newbie.

Were you able to find a solution for this? I have the same exact problem.

Hi @Ankit_Kumar_Jha, I found a way to do it.
I have set-up the discourse-connect url in dashboard settings to the frontend url of my main site.

Let’s say example.com is my frontend site and discuss.example.com is my discourse site. I have set-up the discourse connect url to something like https://example.com/discourse-sso/. From this frontend site URL i am sending a request to my backend API endpoint. In this request i am storing the authorization token in headers.

Voila!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.