Skip to content

Commit bd146d2

Browse files
committed
Merge branch 'refs/heads/graph-conversion'
2 parents 3139e72 + da3a791 commit bd146d2

10 files changed

Lines changed: 159 additions & 823 deletions

File tree

README.md

Lines changed: 20 additions & 629 deletions
Large diffs are not rendered by default.

tutorial/authhelper.py

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file.
1+
# Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE.txt in the project root for license information.
22
from urllib.parse import quote, urlencode
33
import requests
44
import base64
@@ -22,9 +22,10 @@
2222
# The scopes required by the app
2323
scopes = [ 'openid',
2424
'offline_access',
25-
'https://outlook.office.com/mail.read',
26-
'https://outlook.office.com/calendars.read',
27-
'https://outlook.office.com/contacts.read' ]
25+
'User.Read',
26+
'Mail.Read',
27+
'Calendars.Read',
28+
'Contacts.Read' ]
2829

2930
def get_signin_url(redirect_uri):
3031
# Build the query parameters for the signin url
@@ -96,25 +97,4 @@ def get_access_token(request, redirect_uri):
9697
request.session['refresh_token'] = new_tokens['refresh_token']
9798
request.session['token_expires'] = expiration
9899

99-
return new_tokens['access_token']
100-
101-
# MIT License:
102-
103-
# Permission is hereby granted, free of charge, to any person obtaining
104-
# a copy of this software and associated documentation files (the
105-
# ""Software""), to deal in the Software without restriction, including
106-
# without limitation the rights to use, copy, modify, merge, publish,
107-
# distribute, sublicense, and/or sell copies of the Software, and to
108-
# permit persons to whom the Software is furnished to do so, subject to
109-
# the following conditions:
110-
111-
# The above copyright notice and this permission notice shall be
112-
# included in all copies or substantial portions of the Software.
113-
114-
# THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
115-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
116-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
117-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
118-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
119-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
120-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
100+
return new_tokens['access_token']

tutorial/outlookservice.py

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file.
1+
# Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE.txt in the project root for license information.
22
import requests
33
import uuid
44
import json
55

6-
outlook_api_endpoint = 'https://outlook.office.com/api/v2.0{0}'
6+
graph_endpoint = 'https://graph.microsoft.com/v1.0{0}'
77

88
# Generic API Sending
99
def make_api_call(method, url, token, user_email, payload = None, parameters = None):
@@ -38,11 +38,11 @@ def make_api_call(method, url, token, user_email, payload = None, parameters = N
3838
return response
3939

4040
def get_me(access_token):
41-
get_me_url = outlook_api_endpoint.format('/Me')
41+
get_me_url = graph_endpoint.format('/me')
4242

4343
# Use OData query parameters to control the results
44-
# - Only return the DisplayName and EmailAddress fields
45-
query_parameters = {'$select': 'DisplayName,EmailAddress'}
44+
# - Only return the displayName and mail fields
45+
query_parameters = {'$select': 'displayName,mail'}
4646

4747
r = make_api_call('GET', get_me_url, access_token, "", parameters = query_parameters)
4848

@@ -52,15 +52,15 @@ def get_me(access_token):
5252
return "{0}: {1}".format(r.status_code, r.text)
5353

5454
def get_my_messages(access_token, user_email):
55-
get_messages_url = outlook_api_endpoint.format('/Me/MailFolders/Inbox/Messages')
55+
get_messages_url = graph_endpoint.format('/me/mailfolders/inbox/messages')
5656

5757
# Use OData query parameters to control the results
5858
# - Only first 10 results returned
5959
# - Only return the ReceivedDateTime, Subject, and From fields
6060
# - Sort the results by the ReceivedDateTime field in descending order
6161
query_parameters = {'$top': '10',
62-
'$select': 'ReceivedDateTime,Subject,From',
63-
'$orderby': 'ReceivedDateTime DESC'}
62+
'$select': 'receivedDateTime,subject,from',
63+
'$orderby': 'receivedDateTime DESC'}
6464

6565
r = make_api_call('GET', get_messages_url, access_token, user_email, parameters = query_parameters)
6666

@@ -70,15 +70,15 @@ def get_my_messages(access_token, user_email):
7070
return "{0}: {1}".format(r.status_code, r.text)
7171

7272
def get_my_events(access_token, user_email):
73-
get_events_url = outlook_api_endpoint.format('/Me/Events')
73+
get_events_url = graph_endpoint.format('/me/events')
7474

7575
# Use OData query parameters to control the results
7676
# - Only first 10 results returned
7777
# - Only return the Subject, Start, and End fields
7878
# - Sort the results by the Start field in ascending order
7979
query_parameters = {'$top': '10',
80-
'$select': 'Subject,Start,End',
81-
'$orderby': 'Start/DateTime ASC'}
80+
'$select': 'subject,start,end',
81+
'$orderby': 'start/dateTime ASC'}
8282

8383
r = make_api_call('GET', get_events_url, access_token, user_email, parameters = query_parameters)
8484

@@ -88,40 +88,19 @@ def get_my_events(access_token, user_email):
8888
return "{0}: {1}".format(r.status_code, r.text)
8989

9090
def get_my_contacts(access_token, user_email):
91-
get_contacts_url = outlook_api_endpoint.format('/Me/Contacts')
91+
get_contacts_url = graph_endpoint.format('/me/contacts')
9292

9393
# Use OData query parameters to control the results
9494
# - Only first 10 results returned
9595
# - Only return the GivenName, Surname, and EmailAddresses fields
9696
# - Sort the results by the GivenName field in ascending order
9797
query_parameters = {'$top': '10',
98-
'$select': 'GivenName,Surname,EmailAddresses',
99-
'$orderby': 'GivenName ASC'}
98+
'$select': 'givenName,surname,emailAddresses',
99+
'$orderby': 'givenName ASC'}
100100

101101
r = make_api_call('GET', get_contacts_url, access_token, user_email, parameters = query_parameters)
102102

103103
if (r.status_code == requests.codes.ok):
104104
return r.json()
105105
else:
106-
return "{0}: {1}".format(r.status_code, r.text)
107-
108-
# MIT License:
109-
110-
# Permission is hereby granted, free of charge, to any person obtaining
111-
# a copy of this software and associated documentation files (the
112-
# ""Software""), to deal in the Software without restriction, including
113-
# without limitation the rights to use, copy, modify, merge, publish,
114-
# distribute, sublicense, and/or sell copies of the Software, and to
115-
# permit persons to whom the Software is furnished to do so, subject to
116-
# the following conditions:
117-
118-
# The above copyright notice and this permission notice shall be
119-
# included in all copies or substantial portions of the Software.
120-
121-
# THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
122-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
123-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
124-
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
125-
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
126-
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
127-
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
106+
return "{0}: {1}".format(r.status_code, r.text)
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
<html>
2-
<body>
3-
<h1>Your Contacts</h1>
4-
<table width="100%" border="1">
5-
<tr>
6-
<th>First Name</th>
7-
<th>Last Name</th>
8-
<th>Email Address</th>
9-
</tr>
10-
11-
{% for contact in contacts %}
12-
<tr>
13-
<td>{{ contact.GivenName }}</td>
14-
<td>{{ contact.Surname }}</td>
15-
<td>{{ contact.EmailAddresses.0.Address }}</td>
16-
</tr>
17-
{% endfor %}
18-
</table>
19-
</body>
20-
</html>
1+
<!-- Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE.txt in the project root for license information. -->
2+
{% extends "tutorial/layout.html" %}
3+
{% block content %}
4+
<h1>Your Contacts</h1>
5+
<table class="table">
6+
<tr>
7+
<th>First Name</th>
8+
<th>Last Name</th>
9+
<th>Email Address</th>
10+
</tr>
11+
12+
{% for contact in contacts %}
13+
<tr>
14+
<td>{{ contact.givenName }}</td>
15+
<td>{{ contact.surname }}</td>
16+
<td>{{ contact.emailAddresses.0.address }}</td>
17+
</tr>
18+
{% endfor %}
19+
</table>
20+
{% endblock %}
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
<html>
2-
<body>
3-
<h1>Your Events</h1>
4-
<table width="100%" border="1">
5-
<tr>
6-
<th>Subject</th>
7-
<th>Start</th>
8-
<th>End</th>
9-
</tr>
10-
11-
{% for event in events %}
12-
<tr>
13-
<td>{{ event.Subject }}</td>
14-
<td>{{ event.Start }}</td>
15-
<td>{{ event.End }}</td>
16-
</tr>
17-
{% endfor %}
18-
</table>
19-
</body>
20-
</html>
1+
<!-- Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE.txt in the project root for license information. -->
2+
{% extends "tutorial/layout.html" %}
3+
{% block content %}
4+
<h1>Your Events</h1>
5+
<table class="table">
6+
<tr>
7+
<th>Subject</th>
8+
<th>Start</th>
9+
<th>End</th>
10+
</tr>
11+
12+
{% for event in events %}
13+
<tr>
14+
<td>{{ event.subject }}</td>
15+
<td>{{ event.start.dateTime }} ({{ event.start.timeZone }})</td>
16+
<td>{{ event.end.dateTime }} ({{ event.end.timeZone }})</td>
17+
</tr>
18+
{% endfor %}
19+
</table>
20+
{% endblock %}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE.txt in the project root for license information. -->
2+
{% extends "tutorial/layout.html" %}
3+
{% block content %}
4+
<div class="jumbotron">
5+
<h1>Python Outlook Sample</h1>
6+
<p>This example shows how to get an OAuth token from Azure using the <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols-oauth-code" target="_blank">authorization code grant flow</a> and to use that token to make calls to the Outlook APIs.</p>
7+
<p>
8+
<a class="btn btn-lg btn-primary" href="{{signin_url}}" role="button" id="connect-button">Connect to Outlook</a>
9+
</p>
10+
</div>
11+
{% endblock %}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<!-- Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE.txt in the project root for license information. -->
3+
<html>
4+
<head>
5+
<title>Python Outlook API Sample</title>
6+
<!-- Latest compiled and minified CSS -->
7+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
8+
9+
<!-- Optional theme -->
10+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
11+
</head>
12+
<body style="padding-top: 70px;">
13+
<nav class="navbar navbar-inverse navbar-fixed-top">
14+
<div class="container">
15+
<div class="navbar-header">
16+
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
17+
<span class="sr-only">Toggle navigation</span>
18+
<span class="icon-bar"></span>
19+
<span class="icon-bar"></span>
20+
<span class="icon-bar"></span>
21+
</button>
22+
<a class="navbar-brand" href="/">Python Outlook Sample</a>
23+
</div>
24+
<div id="navbar" class="navbar-collapse collapse">
25+
<ul class="nav navbar-nav authed-nav">
26+
<li id='home-nav'><a href="/">Home</a></li>
27+
<li id='inbox-nav'><a href="/tutorial/mail">Inbox</a></li>
28+
<li id='calendar-nav'><a href="/tutorial/events">Calendar</a></li>
29+
<li id='contacts-nav'><a href="/tutorial/contacts">Contacts</a></li>
30+
</ul>
31+
</div>
32+
</div>
33+
</nav>
34+
35+
<div class="container main-container">
36+
{% block content %}{% endblock %}
37+
</div>
38+
39+
</body>
40+
</html>
Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,20 @@
1-
<!-- Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. -->
2-
<html>
3-
<body>
4-
<h1>Your Email</h1>
5-
<table width="100%" border="1">
6-
<tr>
7-
<th>From</th>
8-
<th>Subject</th>
9-
<th>Received</th>
10-
</tr>
11-
12-
{% for message in messages %}
13-
<tr>
14-
<td>{{ message.From.EmailAddress.Name }}</td>
15-
<td>{{ message.Subject }}</td>
16-
<td>{{ message.ReceivedDateTime }}</td>
17-
</tr>
18-
{% endfor %}
19-
</table>
20-
</body>
21-
</html>
22-
23-
<!--
24-
MIT License:
25-
26-
Permission is hereby granted, free of charge, to any person obtaining
27-
a copy of this software and associated documentation files (the
28-
""Software""), to deal in the Software without restriction, including
29-
without limitation the rights to use, copy, modify, merge, publish,
30-
distribute, sublicense, and/or sell copies of the Software, and to
31-
permit persons to whom the Software is furnished to do so, subject to
32-
the following conditions:
33-
34-
The above copyright notice and this permission notice shall be
35-
included in all copies or substantial portions of the Software.
36-
37-
THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
38-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
39-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
40-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
41-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
42-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
43-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44-
-->
1+
<!-- Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE.txt in the project root for license information. -->
2+
{% extends "tutorial/layout.html" %}
3+
{% block content %}
4+
<h1>Your Email</h1>
5+
<table class="table">
6+
<tr>
7+
<th>From</th>
8+
<th>Subject</th>
9+
<th>Received</th>
10+
</tr>
11+
12+
{% for message in messages %}
13+
<tr>
14+
<td>{{ message.from.emailAddress.name }}</td>
15+
<td>{{ message.subject }}</td>
16+
<td>{{ message.receivedDateTime }}</td>
17+
</tr>
18+
{% endfor %}
19+
</table>
20+
{% endblock %}

0 commit comments

Comments
 (0)