I am trying to have an Ouath2 access token based authentication. I am using django-oauth-toolkit
for that. I have registered my app on http://localhost:8000/o/applications
.
However, When I tried to hit the URL http://localhost:8000/o/token/
from the react-app
. I got 401
.
Here is my the useEffect
hook that I used for calling that URL :
useEffect(() => {
// axios.get("api/tests")
// .then((res)=>{
// setUsers(JSON.stringify(res.data))
// })
fetch("http://localhost:8000/o/token/", {
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: client_id,
client_secret: client_secret
}),
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": `Basic ${btoa(client_id+":"+client_secret)}`}
,
method: "POST"
}).then((res)=>{
console.log(res)
})
}, [])
Will look forward to some comments and solutions.