1

My code to get the access token using a refresh token was working fine, but suddenly has stopped working and I'm getting exception as

unauthorized client and status code as 401.

Below is my sample code:

request({
         method: 'POST',
         headers: {
                 'Content-type': 'application/x-www-form-urlencoded'
                    },
        data: {
               client_id: XXXXX,
               client_secret: XXXXX,
               refresh_token: myRefresh_Token_Here,
                grant_type: 'refresh_token'
              },
        URL: "https://oauth2.googleapis.com/token"
      })
                .then(response => {
                    resolve(response);
            })
            .catch(exception => {
                reject(exception);
            });              

Below is the error what i get this i get in below object

exception.response.data
{"error":"unauthorized_client","error_description":"Unauthorized"}'

No other info, also the status code is 401

1
  • Please edit your question and include the full error message there should be more. There are several unauthorized client errors it would be helpful to nail down which one it is you are getting. check for an error description Commented Apr 14, 2021 at 8:49

1 Answer 1

1

unauthorized client

Normally means that the client id and client secret you are using to pair with a refresh token is not the pair that was used to create the refresh token in the first place.

I would double check you have the correct client id and client secret or that someone didn't regenerate your secret on Google cloud console.

Sign up to request clarification or add additional context in comments.

3 Comments

@DalmTo yes indeed, i have checked those possibilities. ClientId ClientSecret are all right, also the same was used to generate the refreshToken
@DalmTo i have observed that, when the access token has expired, and then i try to use refreshToken to get my new accessToken then im getting unauthorized Client, whereas if the accessToken has not expired and if i use the refreshToken to get the new access_token in this case it works fine and i gets the new accessToken
Then the issue is with your Refresh token. I suspect that you did not create this refresh token with this client id, client secret, it could also be that the user has revoked your access. Try generating a new refresh token and test again.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.