Git Product home page Git Product logo

python3-connect-rest-sample's Introduction

[ARCHIVED] Microsoft Graph API Connect Sample for Python

IMPORTANT

This project is being archived and replaced with the Build Python Django apps with Microsoft Graph. As part of the archival process, we're closing all open issues and pull requests.

You can continue to use this sample "as-is", but it won't be maintained moving forward. We apologize for any inconvenience.

Connecting to Office 365 is the first step every app must take to start working with Office 365 services and data. This sample shows how to connect and then call one API through the Microsoft Graph API (previously called Office 365 unified API), and uses the Office Fabric UI to create an Office 365 experience.

Python Connect sample screenshot

Prerequisites

To use the Microsoft Graph API Connect sample for Python, you need the following:

Note: Microsoft has tested the Flask-OAuthlib library in basic scenarios and confirmed that it works with the v2.0 endpoint. Microsoft does not provide fixes for this library and has not done a review of it. Issues and feature requests should be directed to the library’s open-source project.

Register the application

Register an app on the Microsoft App Registration Portal. This generates the app ID and password that you'll use to configure the app for authentication.

  1. Sign into the Microsoft App Registration Portal using either your personal or work or school account.

  2. Choose Add an app.

  3. Enter a name for the app, and choose Create application.

    The registration page displays, listing the properties of your app.

  4. Copy the application ID. This is the unique identifier for your app.

  5. Under Application Secrets, choose Generate New Password. Copy the app secret from the New password generated dialog.

    You'll use the application ID and app secret to configure the app.

  6. Under Platforms, choose Add platform > Web.

  7. Make sure the Allow Implicit Flow check box is selected, and enter http://localhost:5000/login/authorized as the Redirect URI.

    The Allow Implicit Flow option enables the OpenID Connect hybrid flow. During authentication, this enables the app to receive both sign-in info (the id_token) and artifacts (in this case, an authorization code) that the app uses to obtain an access token.

    The redirect URI http://localhost:5000/login/authorized is the value that the OmniAuth middleware is configured to use once it has processed the authentication request.

  8. Choose Save.

Configure and run the app

  1. Using your favorite text editor, open the _PRIVATE.txt file.
  2. Replace ENTER_YOUR_CLIENT_ID with the client ID of your registered application.
  3. Replace ENTER_YOUR_SECRET with the key you generated for your app.
  4. Start the development server by running python manage.py runserver.
  5. Navigate to http://localhost:5000/ in your web browser.

To learn more about this sample, see walkthrough.md.

Contributing

If you'd like to contribute to this sample, see CONTRIBUTING.MD.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Questions and comments

We'd love to get your feedback about the Office 365 Python Connect sample. You can send your questions and suggestions to us in the Issues section of this repository.

Your feedback is important to us. Connect with us on Stack Overflow. Tag your questions with [MicrosoftGraph] and [office365].

Additional resources

Copyright

Copyright (c) 2016 Microsoft. All rights reserved.

python3-connect-rest-sample's People

Contributors

andrewjmay avatar chinmayshah99 avatar davidchesnut avatar jasonjoh avatar martellaj avatar matejak avatar o365devx avatar ricalo avatar tadaomachida avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python3-connect-rest-sample's Issues

Sample implementation of refresh token

Hello,

This is a feature request. For completeness of example, this should have a refresh token which should be requested immediately after login and then subsequently use requests using the refresh tokens

Seems this don´t works

Ive tried today with all steps what say (account, registering app, etc.)

  1. In windows with python3.4 and all flask/request installed
  2. In linux with python 3.5.2

and the results is the same:

flask_oauthlib.client.OAuthException: Invalid response from microsoft

The traceback says
Traceback (most recent call last)

File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1997, in __call__

return self.wsgi_app(environ, start_response)

File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1985, in wsgi_app

response = self.handle_exception(e)

File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1540, in handle_exception

reraise(exc_type, exc_value, tb)

File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in reraise

raise value

File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1982, in wsgi_app

response = self.full_dispatch_request()

File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1614, in full_dispatch_request

rv = self.handle_user_exception(e)

File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1517, in handle_user_exception

reraise(exc_type, exc_value, tb)

File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in reraise

raise value

File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1612, in full_dispatch_request

rv = self.dispatch_request()

File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1598, in dispatch_request

return self.view_functions[rule.endpoint](**req.view_args)

File "/home/jl/Documents/LiClipse Workspace/python3_gui/python3-connect-rest-sample-master/connect/__init__.py", line 54, in authorized

response = microsoft.authorized_response()

File "/usr/local/lib/python3.5/dist-packages/flask_oauthlib/client.py", line 677, in authorized_response

data = self.handle_oauth2_response()

File "/usr/local/lib/python3.5/dist-packages/flask_oauthlib/client.py", line 664, in handle_oauth2_response

 [Open an interactive python shell in this frame] type='invalid_response', data=data

Please, any help will be apreciated.

Thanks.

Indenting is inconsistent

Lots of tabs in the code, then places where there are 2 spaces for the indent. Convention (PEP8) is to use 4 spaces, and never tabs.

Can't access the app registration portal using school account

When I try to follow the instructions to create an app at the registration portal (https://apps.dev.microsoft.com/), I click "register my app" it ask for a sign in, which I do, then it drops me in the microsoft account page(https://account.microsoft.com/?lang=en-US&refd=account.live.com&refp=landing), where I have no option to create an app. Is this a problem with the registration portal, or is the documentation on this project out of date?

Connecting through a proxy

Thanks for this very interesting plugin.
I faced a problem to connect to my SharePoint because my network is through a proxy.
Should it be possible to use the tool behind a proxy ?

Tried this but got a Cookie problem:
ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user(username, password)
request = ClientRequest(ctx_auth)
options = RequestOptions("{0}/_api/web/".format(url))
options.set_header('Accept', 'application/json')
options.set_header('Content-Type', 'application/json')
options.set_header('proxies', {'http':'http://XX.XX.XX.XX:8080',
'https':'https://toto:[email protected]:8080'})
data = request.execute_query_direct(options)

I cannot connect on Graph

Hello, when I click to connect on graph, authorize the app, and it redirect to /login/authorized, it throws this error:

127.0.0.1 - - [19/Oct/2017 20:04:13] "GET /login/authorized?code=OAQABAAIAAABHh4kmS_aKT5Xrjzx...[code continue]...uEJ4PzeucIAA&state=cdd6b425-8bfa-4153-b047-623b99545cf7&session_state=a4982c37-1657-4d49-9229-b6a7db65560c HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/home/mario/miniconda3/envs/onedriveEnv/lib/python3.6/site-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/mario/miniconda3/envs/onedriveEnv/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/home/mario/miniconda3/envs/onedriveEnv/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/mario/miniconda3/envs/onedriveEnv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/mario/miniconda3/envs/onedriveEnv/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/mario/miniconda3/envs/onedriveEnv/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/mario/miniconda3/envs/onedriveEnv/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/mario/miniconda3/envs/onedriveEnv/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
    raise value
  File "/home/mario/miniconda3/envs/onedriveEnv/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/mario/miniconda3/envs/onedriveEnv/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/mario/Projects/python3-connect-rest-sample/connectsample.py", line 66, in authorized
    response = msgraphapi.authorized_response()
  File "/home/mario/miniconda3/envs/onedriveEnv/lib/python3.6/site-packages/flask_oauthlib/client.py", line 677, in authorized_response
    data = self.handle_oauth2_response()
  File "/home/mario/miniconda3/envs/onedriveEnv/lib/python3.6/site-packages/flask_oauthlib/client.py", line 664, in handle_oauth2_response
    type='invalid_response', data=data
flask_oauthlib.client.OAuthException: Invalid response from microsoft

Does this repository still working?

connectsample command fails sending email

Sample flask command allows for connection but fails sending email returning a 404.

Also, warning issued by urllib3 about unverified https request being made.

 * Running on http://localhost:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 194-413-547
127.0.0.1 - - [14/Jun/2017 16:43:02] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [14/Jun/2017 16:43:03] "GET /login HTTP/1.1" 302 -
127.0.0.1 - - [14/Jun/2017 16:43:06] "GET /login/authorized?code=OAQABAAIAAABnfiG-...969d4c517eae HTTP/1.1" 302 -
127.0.0.1 - - [14/Jun/2017 16:43:06] "GET /main HTTP/1.1" 200 -
/home/pchartrand/Envs/msgraph/lib/python3.5/site-packages/urllib3/connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
404: {
  "error": {
    "code": "ResourceNotFound",
    "message": "Resource could not be discovered.",
    "innerError": {
      "request-id": "33de9b29-299f-4c48-a3b1-641d1efaa8c4",
      "date": "2017-06-14T20:43:22"
    }
  }
}
127.0.0.1 - - [14/Jun/2017 16:43:23] "GET /send_mail?emailAddress=xxx%40xxx.ca HTTP/1.1" 200 -

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.