Skip to content

Commit

Permalink
oauth2.py
Browse files Browse the repository at this point in the history
- Extract the site name from the /authorize request Referer
- Remove SITENAME_OAUTH from creds.py
  • Loading branch information
dstaudt committed Jul 17, 2019
1 parent d7478fe commit 63f82e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 0 additions & 1 deletion creds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
PASSWORD = 'CHANGEME'

# Credentials for use with Webex OAuth sites (see oauth2.py)
SITENAME_OAUTH = 'CHANGEME'
WEBEXID_OAUTH = 'CHANGEME' # must include @domain
CLIENT_ID = 'CHANGEME'
CLIENT_SECRET = 'CHANGEME'
12 changes: 9 additions & 3 deletions oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# Authlib==0.11
# Flask==1.0.2
# lxml==4.3.3
# furl==2.0.0

# Dependency installation (you may need to use `pip3` on Linux or Mac):

Expand Down Expand Up @@ -84,10 +85,11 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from flask import Flask, url_for, redirect, session, make_response
from flask import Flask, url_for, redirect, session, make_response, request
from authlib.flask.client import OAuth
from lxml import etree
import requests
from furl import furl

# Edit credentials.py to specify your Webex site/user details
import creds
Expand Down Expand Up @@ -230,7 +232,7 @@ def authorize():
# Go ahead and exchange the auth code for the access token
# and store it in the user session object
try:
session['token'] = webex_meetings.authorize_access_token()
session[ 'token' ] = webex_meetings.authorize_access_token()

except Exception as err:

Expand All @@ -240,6 +242,10 @@ def authorize():

return response, 500

url = furl( request.headers['Referer'] )

session[ 'siteName' ] = url.query.params[ 'site' ]

# Now that we have the API access token, redirect the the URL for making a
# Webex Meetings API GetUser request
return redirect(url_for('GetUser'), code='302')
Expand All @@ -252,7 +258,7 @@ def GetUser():
# access_token from the token object in the session store
try:

reply = WebexGetUser( creds.SITENAME_OAUTH, creds.WEBEXID_OAUTH, session[ 'token' ][ 'access_token' ], debug = False )
reply = WebexGetUser( session[ 'siteName' ], creds.WEBEXID_OAUTH, session[ 'token' ][ 'access_token' ], debug = False )

except SendRequestError as err:

Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
requests==2.21.0
Authlib==0.11
Flask==1.0.2
requests==2.21.0
lxml==4.3.3
furl==2.0.0
Flask==1.0.2

0 comments on commit 63f82e8

Please sign in to comment.