GithubHelp home page GithubHelp logo

azure-samples / active-directory-python-webapp-graphapi Goto Github PK

View Code? Open in Web Editor NEW
35.0 48.0 25.0 70 KB

A Python Web App calling the Microsoft Graph API, leveraging ADAL Python

PowerShell 78.84% Python 19.02% HTML 2.14%
aad python webapp msgraph

active-directory-python-webapp-graphapi's Introduction

Calling Microsoft Graph from a Python web app

There's a newer version of this sample taking advantage of the Microsoft identity platform (formerly Azure AD v2.0) Check it out: https://github.com/Azure-Samples/ms-identity-python-webapp

If you really need to access this Azure AD v1.0, you can navigate to the master branch, but please know that it's no longer supported.

active-directory-python-webapp-graphapi's People

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

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  avatar  avatar  avatar  avatar  avatar  avatar

active-directory-python-webapp-graphapi's Issues

Client secret information should not be saved in tracked source code

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [X ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

The client secret (CLIENT_SECRET) information managed in config.py is handled in an insecure manner. It's way too easy to leak credentials through version control, and should be externalized into an environment variable. At the very least, config.py should be put in the default .gitignore to prevent accidental pushes w/ keys to cloned forks.

Minimal steps to reproduce

Follow the documentation and configure the config.py with the values in your application registration.

Any log messages given by the failure

None.

Expected/desired behavior

Secret information should be managed and consumed via environment variable or through a secrety store like Azure Key Vault.

OS and Version?

ALL

Versions

n/a

Mention any other details that might be useful


Thanks! We'll be in touch soon.

App received 400 error when running sample

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Follow instructions in README. (Create app registration, insert data into config.py, call localhost:5000 in browser)

Any log messages given by the failure

werkzeug.exceptions.BadRequestKeyError
werkzeug.exceptions.HTTPException.wrap.<locals>.newcls: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

Traceback (most recent call last)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2328, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2314, in wsgi_app
response = self.handle_exception(e)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1760, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 36, in reraise
raise value
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 2311, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1834, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1737, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/site-packages/flask/_compat.py", line 36, in reraise
raise value
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1832, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1818, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/thfalgou/git/Azure-Samples/active-directory-python-webapp-graphapi/app.py", line 44, in main_logic
code = flask.request.args['code']
File "/usr/local/lib/python3.7/site-packages/werkzeug/datastructures.py", line 442, in __getitem__
raise exceptions.BadRequestKeyError(key)
werkzeug.exceptions.HTTPException.wrap.<locals>.newcls: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

Expected/desired behavior

Expected not to receive 400 error

OS and Version?

OSX

Versions

OSX 10.12

Mention any other details that might be useful

I'm using the microsoft.onmicrosoft.com tenant (as an blue-badge employee)

/groups?$filter=startswith(displayName, 'AA') resulting in Bad Request

I have this simple search function in Flask to lookup groups names but it always ends up in a result saying badly formed request and a status: 400.

@APP.route('/search')
def search(top=10):
params = request.args.to_dict()
term = params.get('term')
queryMembers = "groups?$filter=startswith(displayName, 'AA')"
print("AAA", queryMembers)
result = MSGRAPH.get(queryMembers, headers=request_headers()).data
return flask.render_template('query_2.html', result=result)

need help on figuring out what wrong I am doing.

/graphcall doesn't do any auth validation

There is a serious security issue with this sample. The /graphcall doesn't do any auth validation. The session object at https://github.com/Azure-Samples/active-directory-python-webapp-graphapi/blob/master/app.py#L13 is global and it will be used for any /graphcall call. So once someone authenticates, any subsequent calls to /graphcall use the same auth token.

This issue is for a: (mark with an x)

- [x ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

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.