Created
July 14, 2019 01:37
-
-
Save simonw/46e39495761e63c7ede2811c0782ac07 to your computer and use it in GitHub Desktop.
datasette_auth_github middleware example, from https://simonwillison.net/2019/Jul/14/sso-asgi/
This file contains 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
from datasette_auth_github import GitHubAuth | |
from starlette.applications import Starlette | |
from starlette.responses import HTMLResponse | |
import uvicorn | |
app = Starlette(debug=True) | |
@app.route("/") | |
async def homepage(request): | |
return HTMLResponse("Hello, {}".format( | |
repr(request.scope["auth"]) | |
)) | |
authenticated_app = GitHubAuth( | |
app, | |
client_id="986f5d837b45e32ee6dd", | |
client_secret="...", | |
require_auth=True, | |
allow_users=["simonw"], | |
) | |
if __name__ == "__main__": | |
uvicorn.run(authenticated_app, host="0.0.0.0", port=8000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment