Skip to content

Commit

Permalink
added automatic SCM versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbode committed Oct 29, 2018
1 parent 8674009 commit bf558f3
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 8 deletions.
70 changes: 64 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,67 @@
# Dash Google Auth
Basic example of using Google OAuth to authenticate and view a [Dash](https://dash.plot.ly/) app. Uses [flask dance](https://github.com/singingwolfboy/flask-dance) and a modified version of Plotly's own [dash auth](https://github.com/plotly/dash-auth) for authentication.

Dash Google Auth is a simple library using Google OAuth to authenticate and
view a [Dash](https://dash.plot.ly/) app.

This Library uses [Flask Dance](https://github.com/singingwolfboy/flask-dance)
and a modified version of Plotly's own [dash auth](https://github.com/plotly/dash-auth)
for authentication.

## Basic Use

Authentication can be added to your Dash application using the `GoogleOAuth`
class, i.e.

```python
from dash import Dash
from flask import Flask
from dash_google_auth import GoogleOAuth

server = Flask(__name__)
server.config.update({
'GOOGLE_OAUTH_CLIENT_ID': ...,
'GOOGLE_OAUTH_CLIENT_SECRET': ...,
})

app = Dash(__name__, server=server, url_base_pathname='/', auth='auth')

authorized_emails = [...]
additional_scopes = [...]
auth = GoogleOAuth(app, authorized_emails, additional_scopes)

# your Dash app here :)
...
```

## Example
Steps to try this out yourself:
1. Set up a virtual environment and install the requirements (tested only with Python 2.7)
2. Follow the [Flask Dance Guide](http://flask-dance.readthedocs.io/en/latest/quickstarts/google.html) to create an app on the google admin console
3. Replace the variables for *server.config["GOOGLE_OAUTH_CLIENT_ID"]* and *server.config["GOOGLE_OAUTH_CLIENT_SECRET"]* in [init.py](./app/__init__.py) with values from the Google OAuth 2 client you should have set up in step 1. If you've set these up properly, you can find them at [https://console.developers.google.com/apis/credentials](https://console.developers.google.com/apis/credentials) under the section **OAuth 2.0 client IDs**
4. Replace authorized_emails from [init.py](./app/__init__.py) with whatever google emails you want to grant access to your app. In production, I'd recommend getting these from a database instead.
5. Run `python app.py` and open [localhost](http://localhost:8050/) in a browser window to try it out! If the app loads automatically without prompting a google login, that means you're already authenticated -- try using an incogntio window in this case if you want to see the login experience for a new user.

1. Install the `dash-google-auth` library using `pip`:

```bash
$ pip install dash-google-auth
```

2. Follow the [Flask Dance Guide](http://flask-dance.readthedocs.io/en/latest/quickstarts/google.html)
to create an app on the google admin console

3. Make a copy of [app.py](https://github.com/lucaschapin/dash-google-auth/blob/master/app.py)
and set the variables (or set the corresponding environment variables):
```python
server.config["GOOGLE_OAUTH_CLIENT_ID"] = ...
server.config["GOOGLE_OAUTH_CLIENT_SECRET"] = ...
```
with values from the Google OAuth 2 client you should have set up in step 1.
If you've set these up properly, you can find them at
[APIs & Services > Credentials](https://console.developers.google.com/apis/credentials)
under the section **OAuth 2.0 client IDs**.
4. Replace `authorized_emails` in `app.py` with whatever
Google emails you want to grant access to your app. In production, I'd
recommend getting these from a database instead.

5. Run `python app.py` and open [localhost](http://localhost:8050/) in a
browser window to try it out! If the app loads automatically without
prompting a Google login, that means you're already authenticated -- try
using an incognito window in this case if you want to see the login
experience for a new user.
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ def MyDashApp():
])

if __name__ == '__main__':
app.run_server()
app.run_server(host='localhost')
7 changes: 7 additions & 0 deletions dash_google_auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@
Dash Google Authentication.
"""

import pkg_resources
try:
__version__ = pkg_resources.get_distribution(__name__.replace('.', '-')).version
except pkg_resources.DistributionNotFound:
__version__ = None
del pkg_resources

from .google_oauth import GoogleOAuth
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

setup(
name="dash-google-auth",
version='0.1.0',
description="Dash Google Auth",
long_description=open('README.md', 'r').read().strip(),
long_description_content_type='test/markdown',
Expand All @@ -21,10 +20,13 @@
'Flask-Dance>=0.14.0',
'six>=1.11.0',
],
setup_requires=['pytest-runner', 'setuptools_scm'],
tests_require=['pytest'],
classifiers=[
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: Implementation :: CPython',
],
use_scm_version=True,
zip_safe=False,
)

0 comments on commit bf558f3

Please sign in to comment.