Getting 401 error : "invalid_client" in django-oauth-toolit

278 views Asked by At

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.

enter image description here

However, When I tried to hit the URL http://localhost:8000/o/token/ from the react-app . I got 401.

enter image description here

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.

1

There are 1 answers

0
Ashish Tripathi On

I got the solution. Actually I was Using the encrypted version of the client secret. I forgot to copy it before saving. Once it is saved the value is encrypted. So it's better to copy it somewhere prior saving it.