forked from microsoftgraph/python-sample-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample_graphrest.py
44 lines (35 loc) · 1.38 KB
/
sample_graphrest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""graphrest sample for Microsoft Graph"""
# Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
# See LICENSE in the project root for license information.
import os
import bottle
import graphrest
MSGRAPH = graphrest.GraphSession()
bottle.TEMPLATE_PATH = ['./static/templates']
@bottle.route('/')
@bottle.view('homepage.html')
def homepage():
"""Render the home page."""
return {'sample': 'graphrest'}
@bottle.route('/login')
def login():
"""Prompt user to authenticate."""
MSGRAPH.login('/graphcall')
@bottle.route('/login/authorized')
def authorized():
"""Handler for the application's Redirect Uri."""
MSGRAPH.redirect_uri_handler()
@bottle.route('/graphcall')
@bottle.view('graphcall.html')
def graphcall():
"""Confirm user authentication by calling Graph and displaying some data."""
endpoint = MSGRAPH.api_endpoint('me')
graphdata = MSGRAPH.get(endpoint).json()
return {'graphdata': graphdata, 'endpoint': endpoint, 'sample': 'graphrest'}
@bottle.route('/static/<filepath:path>')
def server_static(filepath):
"""Handler for static files, used with the development server."""
root_folder = os.path.abspath(os.path.dirname(__file__))
return bottle.static_file(filepath, root=os.path.join(root_folder, 'static'))
if __name__ == '__main__':
bottle.run(app=bottle.app(), server='wsgiref', host='localhost', port=5000)