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
- Prepare
- Create Webex Integration (oAuth)
- Update script
- Run script
- Result
Then:
1. Prepare
- Download & Install Python 3.6 or higher
- Install Flask: system wide or in a
virtual environment (if you don't know what that is, ignore it)
- 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"
- 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
- https://developer.webex.com
- Login
- "My Webex Apps" (click your Avatar on the top right)
- Create a New App
- Integration
- Integration name: pick a useful and descriptive name
- Contact email: your account email
- Icon: select one
- Description: tell yourself what you are testing
- Redirect URI: the URL that Webex needs to go to when you authenticated succesfully
(http://127.0.0.1:5000/gologin) (thanks muthvar1!)
- Scopes: spark:people_read
- Add integration
3. Update Code
- 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!)
- Open the Python script and paste the Client_Id and Client_Secret in the variables.
4. Start Code
- In a terminal window (or command prompt), go to the folder that contains your script
- Run the script "Python python-oauth.py" (or "Python3" if you also have Python v2)
- You should see Flask starting and waiting to work
- Open a browser and go to http://127.0.0.1:5000
- Click "here" to login and see what happens.
5. Result
- 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)
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