Skip to content

Commit

Permalink
Add syntax highlighting to the README
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Friend committed Oct 4, 2015
1 parent c788173 commit 5c058b5
Showing 1 changed file with 55 additions and 51 deletions.
106 changes: 55 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,69 @@ Simple extension that provides Basic and Digest HTTP authentication for Flask ro
Basic authentication example
----------------------------

from flask import Flask
from flask_httpauth import HTTPBasicAuth

app = Flask(__name__)
auth = HTTPBasicAuth()

users = {
"john": "hello",
"susan": "bye"
}

@auth.get_password
def get_pw(username):
if username in users:
return users.get(username)
return None

@app.route('/')
@auth.login_required
def index():
return "Hello, %s!" % auth.username()
if __name__ == '__main__':
app.run()
```python
from flask import Flask
from flask_httpauth import HTTPBasicAuth

app = Flask(__name__)
auth = HTTPBasicAuth()

users = {
"john": "hello",
"susan": "bye"
}

@auth.get_password
def get_pw(username):
if username in users:
return users.get(username)
return None

@app.route('/')
@auth.login_required
def index():
return "Hello, %s!" % auth.username()

if __name__ == '__main__':
app.run()
```

Note: See the [documentation](http://pythonhosted.org/Flask-HTTPAuth) for more complex examples that involve password hashing and custom verification callbacks.

Digest authentication example
-----------------------------

from flask import Flask
from flask_httpauth import HTTPDigestAuth

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret key here'
auth = HTTPDigestAuth()

users = {
"john": "hello",
"susan": "bye"
}

@auth.get_password
def get_pw(username):
if username in users:
return users.get(username)
return None
@app.route('/')
@auth.login_required
def index():
return "Hello, %s!" % auth.username()
if __name__ == '__main__':
app.run()
```python
from flask import Flask
from flask_httpauth import HTTPDigestAuth

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret key here'
auth = HTTPDigestAuth()

users = {
"john": "hello",
"susan": "bye"
}

@auth.get_password
def get_pw(username):
if username in users:
return users.get(username)
return None

@app.route('/')
@auth.login_required
def index():
return "Hello, %s!" % auth.username()

if __name__ == '__main__':
app.run()
```

Resources
---------

- [Documentation](http://pythonhosted.org/Flask-HTTPAuth)
- [pypi](https://pypi.python.org/pypi/Flask-HTTPAuth)
- [pypi](https://pypi.python.org/pypi/Flask-HTTPAuth)

0 comments on commit 5c058b5

Please sign in to comment.