Skip to main content
Question

OAU-213 TokenInvalid, while calling refresh token

  • January 27, 2023
  • 1 reply
  • 425 views

We are using the OAuth Authorization Code flow, although while calling the refresh token, even when the refresh token is valid.

The access token is valid and works with other APIs when it is valid, although when we call API for a refresh token, it is giving us an invalid token.

I checked the forum for the solutions, although neither the token seems to be corrupted, nor the password has changed. Can you please assist us with the same?

I am attaching the code for the same below:

Authorization Code to get access token:

self.url = f"{self.API_Server_URL}/restapi/oauth/tok
clientId_clientSecret =f"{self.rc_clientId}:{self.rc_clientSecret}"
clientId_clientSecret_bytes = clientId_clientSecret.encode("ascii")
base64_bytes = base64.b64encode(clientId_clientSecret_bytes)
base64_clientId_clientSecret = base64_bytes.decode("ascii")

            headers = {
                "Authorization": f"Basic {base64_clientId_clientSecret}"
            }

            params = {
                "grant_type": "authorization_code",
                "code": code,
                "redirect_uri": self.redirect_uri + "/ringcentral/auth",
                "client_id": self.rc_clientId,
                "client_secret": self.rc_clientSecret,
                "refresh_token_ttl":604800
            }

            responseData = requests.post(self.url, headers=headers, data=params)


Code used for getting refresh token:

clientId_clientSecret = f"{rc_clientId}:{rc_clientSecret}"
 clientId_clientSecret_bytes = clientId_clientSecret.encode("ascii")
            base64_bytes = base64.b64encode(clientId_clientSecret_bytes)
            base64_clientId_clientSecret = base64_bytes.decode("ascii")
            brand_type = obj.get('brand_type')
            
            url = f"{API_Server_URL}/restapi/oauth/token"

            if brand_type:
                url = url.replace(".com", ".biz")

            headers = {
                "Content-Type": "application/x-www-form-urlencoded",
                "Accept": "application/json",
                "Authorization": f"Basic {base64_clientId_clientSecret}"
            }
            params = {
                "refresh_token": obj.get("refresh_token"),
                "grant_type": "refresh_token",
                "endpoint_id": obj.get("endpoint_id")
            }

            responseData = requests.post(url, headers=headers, data=params)

1 reply

PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • 2313 replies
  • January 27, 2023

Fix these first and run again to see if it helps

// Login body params
   params = {
                "grant_type": "authorization_code",
                "code": code,
                "redirect_uri": self.redirect_uri + "/ringcentral/auth"
                // "refresh_token_ttl":604800 // Unneccessary
            }
// Refresh body
   params = {
                "refresh_token": obj.get("refresh_token"),
                "grant_type": "refresh_token"               
            }

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings