44
44
from webexteamssdk import WebexTeamsAPI
45
45
46
46
# Parameters configured in Webex Integration
47
- OAUTH_CLIENT_ID = "your integration client ID"
47
+ OAUTH_CLIENT_ID = "your integration Client ID"
48
48
OAUTH_CLIENT_SECRET = "your integration Client Secret"
49
49
OAUTH_CALLBACK_URI = "http://localhost:5000/callback"
50
50
# Scopes are space-separated. Can use any subset of the configured scopes.
54
54
oauth_authorizationUri = "https://webexapis.com/v1/authorize?"
55
55
oauth_tokenUri = "https://webexapis.com/v1/access_token"
56
56
57
-
58
- # Get the ngrok public URI. It can be used instead of the localhost URI, as long
59
- # as it is also configured in the Webex integration
60
- r = requests .get ("http://localhost:4040/api/tunnels" )
61
- public_url = r .json ()['tunnels' ][0 ]['public_url' ]
57
+ # On a local machine, this script will run even without a public callback URI.
58
+ # But in reality the user is never on the same computer with the server. To
59
+ # enablre remote user access, an Ngrok public URI has be used instead of the
60
+ # local URI.
61
+ # Uncomment the lines below to automatically get the public URI from
62
+ # ngrok and use it instead of the local one. This public URI must also be
63
+ # configured in the Webex Integration as a Redirect URI.
64
+ #
65
+ # r = requests.get("http://localhost:4040/api/tunnels")
66
+ # public_url = r.json()['tunnels'][0]['public_url']
62
67
# OAUTH_CALLBACK_URI = public_url + "/callback"
63
68
64
69
# Create Flask app instance
68
73
app .secret_key = "very bad secret"
69
74
70
75
71
- # Welcome page. Link to auth from this page.
76
+ # Welcome page. Link to auth from this page, or from anywhere else .
72
77
@app .route ("/" )
73
78
def root ():
74
79
print ("/ requested" )
75
80
return ("""
76
81
<p>Hey, this is Flask!</p>
77
- <p>Click <a href="{}">here</a> to authenticate Webex integration .</p>
82
+ <p>Click <a href="{}">here</a> to authorize Webex Integration .</p>
78
83
""" .format (url_for ("auth" )))
79
84
80
85
81
86
# OAuth Step 1 - Build authorization URL and redirect user.
82
- # Redirect the user/resource owner to the OAuth provider using an URL with a few
83
- # key OAuth parameters.
87
+ # Redirect the user/resource owner to the OAuth provider (Webex) using an URI
88
+ # with a few key OAuth parameters.
84
89
@app .route ("/auth" )
85
90
def auth ():
86
91
print ("Authorization requested" )
@@ -109,9 +114,9 @@ def auth():
109
114
110
115
# OAuth Step 3 - Receive authoriation code and obtain access token.
111
116
# The user has been redirected back from the provider to your registered
112
- # callback URL . With this redirection comes an authorization code included
113
- # in the redirect URL . We will use that code to obtain an access token.
114
- # The access token can be then used for any API calls within the authorized scopes.
117
+ # callback URI . With this request comes an authorization code included in the
118
+ # redirect URI . We will use that code to obtain an access token. The access
119
+ # token can be then used for any API calls within the authorized scopes.
115
120
@app .route ("/callback" , methods = ["GET" ])
116
121
def callback ():
117
122
print ("OAuth callback received" )
@@ -136,7 +141,7 @@ def callback():
136
141
137
142
# 1.
138
143
# The API connection can be directly initialized with OAuth information. It
139
- # will exchange the OAuth authorization code to access token behind the
144
+ # will exchange the OAuth authorization code to an access token behind the
140
145
# scenes. It is the easiest, but the drawback is the refresh token is lost
141
146
# and cannot be saved.
142
147
api = WebexTeamsAPI (
0 commit comments