News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
OAU-213 TokenInvalid, while calling refresh token
Tags: oauth, get token, authentication
Jan 26, 2023 at 5:02pm   •   1 replies  •  0 likes
Avijit Chauhan

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 Answer
answered on Jan 27, 2023 at 11:01am  

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"               
            }

 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us