Auth0 Django Quickstart
https://auth0.com/docs/quickstart/webapp/django/01-login
#Django #Auth0
https://github.com/auth0-samples/auth0-django-web-app/tree/master/01-Login
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
Django OAuth Client (authlib)
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と代入
👉DjangoのHttpRequest
/logoutに対応するビュー
/homeに対応するビュー
ただしdjango.contrib.auth.decorators.login_requiredは使えない
https://community.auth0.com/t/how-to-make-auth0-users-to-pass-login-required-decorator-in-django/104203/4
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.