Skip to content

Instantly share code, notes, and snippets.

@scribu
Last active Aug 11, 2016
Embed
What would you like to do?
Basic Auth Test
<script>
fetch('/secrets', {credentials: 'same-origin'}).then((response) => alert('Worked!'));
</script>
flask-basicauth==0.2.0
flask==0.11.1
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)
@scribu
Copy link
Author

scribu commented Aug 11, 2016

This is a quick check to see if it's possible to load JSON from a file that's secured using basic auth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment