Auth0 Django Quickstart
Auth0の設定
Auto0のapplication
Domain
Client ID
Client Secret
Callback URL: http://127.0.0.1:3000/callback
Logout URL: http://127.0.0.1:3000
Django applicationを作っていく
django-admin startproject webappexample
requestsが必要
django-environでも動かせた
code:.env
AUTH0_CLIENT_ID=
AUTH0_CLIENT_SECRET=
AUTH0_DOMAIN=
プロジェクトのsettings.py
TEMPLATE_DIRを追加している
アプリケーションのviews.py
from authlib.integrations.django_client import OAuth
/loginに対応するビュー
/callbackに対応するビュー
request.session["user"] = tokenと代入
/logoutに対応するビュー
/homeに対応するビュー
I wrote a small function that gets email from request.session.get(“user”), and then find the user. If the user is new, then create one. Set the “user” in the context before render.