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
New to the api ,new to using api need some help in writing a simple python code to retrieve oauth token
Tags: authorization
Mar 25, 2021 at 3:18pm   •   3 replies  •  0 likes
Sagar Arora

Can someone please help me writing a simple python script to get the oauth token using api.

,

need some help in writing a simple python code to retrieve oauth token

3 Answers
answered on Mar 29, 2021 at 2:33pm  

I don't know what you want to refer to. That code is the RingCentral Python SDK, which helps developers easier to login RingCentral platform. It can be used to login with password flow or OAuth authorization.

To be honest, I don't know what you want to do as your original question is about how to retrieve auth token.

After you log in either ways, you will get the access tokens. And this sample code helps you to achieve the tokens via OAuth. Your problem is you don't know Flask so you cannot use the code as such. But it should help with the basic steps.

https://developers.ringcentral.com/guide/authentication/quick-start#python


@app.route('/oauth2callback', methods=['GET'])
def oauth2callback():
    platform = rcsdk.platform()
    auth_code = request.values.get('code')
    platform.login('', '', '', auth_code, RINGCENTRAL_REDIRECT_URL)
    tokens = platform.auth().data()
    session['sessionAccessToken'] = tokens
    return render_template('test.html')

 0
answered on Mar 25, 2021 at 4:54pm  

See this tutorial. Or this quick started sample using the Python SDK.


 0
answered on Mar 25, 2021 at 10:42pm  

Is there a example without using the sdk

because when i use SDK i keep getting this error

ImportError: cannot import name 'SDK' from partially initialized module 'ringcentral' (most likely due to a circular import)


 0
on Mar 26, 2021 at 6:42am   •  0 likes

That is the tutorial is about "Access RingCentral platform services using Python native API."

on Mar 26, 2021 at 8:05am   •  0 likes

Will the app password work in this scenario?

on Mar 26, 2021 at 8:40am   •  0 likes

It depends on the account SSO settings. Most of the cases is that it'll not support password flow after enabling SSO.

Implement 3-legged authentication login requires you writing lots of codes. That is why I recommend you to use the SDK. Your problem is your environment and I don't know how you set/install the RingCentral Python SDK. you should solve that problem or then look at the source code of the SDK to implement your own. https://github.com/ringcentral/ringcentral-python

on Mar 26, 2021 at 10:48am   •  0 likes

so just a question for 3 legged autorization. What does this

auth_code = request.values.get('code') suppose to return. Ad what if we are not using flask. What will it be equivalent of lets say if we are using requests library

on Mar 26, 2021 at 10:54am   •  0 likes

3-legged authorization is just another way to say OAuth 2.0. Search the term to learn more about it if you don't know.

Flask is just a Python Web framework. You can use Django, Web2py or whatever framework you like. It is not a requirement.

on Mar 29, 2021 at 8:33am   •  0 likes

How to create a api key. That i can use as auth token?

on Mar 29, 2021 at 12:56pm   •  0 likes

We don't use API key. We use app client id and client secret instead. You use the client id and secret with the user login credentials (username and password) to get an access token and use the access token to call the platform APIs.

on Mar 29, 2021 at 12:58pm   •  0 likes

But i don't have password as our account is sso enabled. So how should i will get access token.

on Mar 29, 2021 at 2:20pm   •  0 likes

That was why I told you about 3-legged authorization. We have an intention to support API key but it is an upcoming feature.

on Mar 29, 2021 at 2:22pm   •  0 likes

Yeah but in 3 legged authorization you have to spin up an server. is that correct or is there any other way around and also what is this code that is being referred here in the GitHub.
https://github.com/ringcentral/ringcentral-python/blob/758084a2e602efcb0f23f5369f827ea8389be58f/ringcentral/platform/platform.py#L98

on Mar 29, 2021 at 12:54pm   •  0 likes
on Mar 26, 2021 at 6:45am   •  0 likes

So the thing with native api example is that it needs 'password': os.getenv("RC_PASSWORD")

but we have enabled sso on our account so how will that work?



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