Last active
August 11, 2016 12:03
-
-
Save scribu/5b700bdff2c1f5360a8e9b2ce85b16c7 to your computer and use it in GitHub Desktop.
Basic Auth Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
fetch('/secrets', {credentials: 'same-origin'}).then((response) => alert('Worked!')); | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flask-basicauth==0.2.0 | |
flask==0.11.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from flask import Flask | |
from flask_basicauth import BasicAuth | |
app = Flask(__name__) | |
app.config['BASIC_AUTH_USERNAME'] = 'john' | |
app.config['BASIC_AUTH_PASSWORD'] = 'matrix' | |
basic_auth = BasicAuth(app) | |
@app.route('/') | |
@basic_auth.required | |
def index(): | |
return open('index.html').read() | |
@app.route('/secrets') | |
@basic_auth.required | |
def secrets(): | |
return json.dumps({ | |
'token': 'abc' | |
}) | |
if __name__ == '__main__': | |
app.run(port=8000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a quick check to see if it's possible to load JSON from a file that's secured using basic auth.