published

Webex Message Flask oAuth Integration

Example code of Python with Flask to do Webex Message (Teams) authentication using oAuth. This example uses Flask, a tiny webserver in Python.

Start

  1. Prepare
  2. Create Webex Integration (oAuth)
  3. Update script
  4. Run script
  5. Result

Then:

1. Prepare

  1. Download & Install Python 3.6 or higher
  2. Install Flask: system wide or in a
    virtual environment (if you don't know what that is, ignore it)
  3. Test your setup: type "Python -V" and check the version number.
    • version >3.6 or higher: continue
    • version <3.6: try again with "Python3 -V"
  4. In Python type "import flask" and press enter. If there's no error message, continue, otherwise troubleshoot.

In case you're wondering: how does oauth work?

2. Create Webex integration

  1. https://developer.webex.com
  2. Login
  3. "My Webex Apps" (click your Avatar on the top right)
  4. Create a New App
  5. Integration
  6. Integration name: pick a useful and descriptive name
  7. Contact email: your account email
  8. Icon: select one
  9. Description: tell yourself what you are testing
  10. Redirect URI: the URL that Webex needs to go to when you authenticated succesfully
    (http://127.0.0.1:5000/gologin) (thanks muthvar1!)
  11. Scopes: spark:people_read
  12. Add integration

3. Update Code

  1. With the new integration in place, copy the Client_Id and Client_Secret (be careful that you don't confuse
    these with the 'Integration ID' that's also displayed!)
  2. Open the Python script and paste the Client_Id and Client_Secret in the variables.

4. Start Code

  1. In a terminal window (or command prompt), go to the folder that contains your script
  2. Run the script "Python python-oauth.py" (or "Python3" if you also have Python v2)
  3. You should see Flask starting and waiting to work
  4. Open a browser and go to http://127.0.0.1:5000
  5. Click "here" to login and see what happens.

5. Result

  • First page

                

  • Click 'here', redirect to Webex Message, Authenticate, then click "Accept" to allow your code to 'do stuff on your behalf' (using the oAuth access token to retrieve your name and email address)

                

  • The result

                

Tips

  • Mac users: use the Atom editor and make sure it has Python syntax highlighting
    (BTW, one of my favourite packages is "highlight-selected")
  • Windows users: Notepad++

Next

Take a look at the code! I've tried to keep it as simple as possible. When reading it you should be able to understand what's happening and which steps are taken. Also look at the oAuth flow image below
Look at these other resources:

How does oAuth work?

I've taken one of the summary slides from my oAuth presentations.

                         

More projects...

...more information posted here:

Enjoy!
DJ

View code on GitHub
  • Owner

  • Contributors

    +1Github contributor
  • Categories

  • Products

    Webex
  • Programming Languages

    Python
  • License

    Other

Code Exchange Community

Get help, share code, and collaborate with other developers in the Code Exchange community.View Community
Disclaimer:
Cisco provides Code Exchange for convenience and informational purposes only, with no support of any kind. This page contains information and links from third-party websites that are governed by their own separate terms. Reference to a project or contributor on this page does not imply any affiliation with or endorsement by Cisco.