Skip to content

Instantly share code, notes, and snippets.

@scribu
Last active August 11, 2016 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scribu/5b700bdff2c1f5360a8e9b2ce85b16c7 to your computer and use it in GitHub Desktop.
Save scribu/5b700bdff2c1f5360a8e9b2ce85b16c7 to your computer and use it in GitHub Desktop.
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