Skip to content

Commit

Permalink
Python 3 branch
Browse files Browse the repository at this point in the history
Extended gitignore for Flask, pipenv
Updated templates with new DTC locations
Updated for Python 3 libraries and syntax
Fixed unused dependencies
Moved to pipenv
Improve clarity of setup instructions
Better error reporting
  • Loading branch information
andypiper committed Feb 6, 2019
1 parent 2b684a1 commit b2a23ad
Show file tree
Hide file tree
Showing 10 changed files with 416 additions and 97 deletions.
130 changes: 127 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,128 @@
venv
*.pyc
*.backup
# Created by https://www.gitignore.io/api/flask
# Edit at https://www.gitignore.io/?templates=flask

### Flask ###
instance/*
!instance/.gitignore
.webassets-cache

### Flask.Python Stack ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# End of https://www.gitignore.io/api/flask

config.cfg
.vscode
19 changes: 19 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
gunicorn = "*"
"httplib2" = "*"
itsdangerous = "*"
"oauth2" = "*"
Flask = "*"
"Jinja2" = "*"
MarkupSafe = "*"
Werkzeug = "*"

[dev-packages]

[requires]
python_version = "3"
117 changes: 117 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
twauth-web
==========
# twauth-web

A simple Python+Flask web app that demonstrates the flow of obtaining a Twitter user OAuth access token.
A simple Python + Flask web app that demonstrates the flow of obtaining a [Twitter user OAuth access token](https://developer.twitter.com/en/docs/basics/authentication/overview/oauth).

### Reference
## Setup

[Twitter Developer Portal](https://dev.twitter.com/)
1. Obtain consumer key and secret from the Twitter Developer portal. The app should be configured to enable Sign in with Twitter. See `twauth-web.py` for more details, but you can either:
1. add these values to a `config.cfg` file (local); or
2. set environment variables `TWAUTH_APP_CONSUMER_KEY` and `TWAUTH_APP_CONSUMER_SECRET` (cloud or local)
2. Setup a [pipenv](https://pipenv.readthedocs.io/en/latest/) environment, and install dependencies:
1. `pipenv install`
2. `pipenv shell`
3. Start the app:
1. `python3 ./twauth-web.py`; or
2. `gunicorn twauth-web:app`

Note: the app must have an externally-accessible URL (i.e do not attempt to connect via localhost). You can run a tunnel e.g. `ngrok` for local use, or deploy to a cloud environment such as Heroku (a `Procfile` is included).

Open a browser window on your demo app's external URL. Don't click the buttons yet!

Finally, revisit the dev portal, and add your app's callback URL (`http[s]://your-deployed-url/callback`) to the callback URL whitelist setting, before attempting to click through the demo pages.

## Reference

[Twitter Developer Portal](https://developer.twitter.com/)
[Flask](http://flask.pocoo.org/)
[python-oauth2](https://github.com/simplegeo/python-oauth2)
[Bootstrap](http://getbootstrap.com/)

### Contact
### Credits

Jacob Petrie
Original version by Jacob Petrie
https://twitter.com/jaakkosf
https://github.com/jaakko-sf/twauth-web
9 changes: 0 additions & 9 deletions requirements.txt

This file was deleted.

29 changes: 17 additions & 12 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>twauth-web sample app {% block title %}{% endblock %}</title>
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
</head>

<body>
<div class="container">
<h1>twauth-web</h1>
{% block containercontent %}{% endblock %}
<head>
<title>twauth-web sample app {% block title %}{% endblock %}</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
</head>

<body>
<div class="container">
<h1>twauth-web</h1>
{% block containercontent %}{% endblock %}
<hr>
<div class="footer">
<p class="text-muted"><small>This is a basic demo created by <a href="https://twitter.com/jaakkosf">@jaakkosf</a> from the <a href="https://twitter.com/twitterapi">@twitterapi</a> team. It is written in Python, using <a href="http://flask.pocoo.org/">Flask</a> and <a href="https://github.com/simplegeo/python-oauth2">python-oauth2</a>. Basic CSS is provided by <a href="http://getbootstrap.com/">Bootstrap</a>. The source code for this project can be found at <a href="https://github.com/jaakko-sf/twauth-web">github/jaakko-sf/twauth-web</a>.</small></p>
<p class="text-muted"><small>This is a basic demo created by the <a href="https://twitter.com/TwitterDev">@TwitterDev</a>
team. It is written in Python, using <a href="http://flask.pocoo.org/">Flask</a>
and <a href="https://github.com/simplegeo/python-oauth2">python-oauth2</a>. Basic CSS is provided by <a href="http://getbootstrap.com/">Bootstrap</a>.
The source code for this project can be found at <a href="https://github.com/twitterdev/twauth-web">github/twitterdev/twauth-web</a>.</small></p>
</div>
</div>
</body>
</html>
</div>
</body>

</html>
Loading

0 comments on commit b2a23ad

Please sign in to comment.