【发布时间】:2021-09-05 10:41:02
【问题描述】:
我需要使用我的 django 应用程序中的 firebase 登录用户。我已经完成了我认为我需要做的事情,但我似乎遗漏了一些东西。我正在使用 pyrebase 库。我在 firebase 上创建了一个用户并且现在我需要让他们登录。 我在 Postman 上发布了电子邮件和密码,我得到了“idToken”和“refreshToken”,这意味着用户在 firebase 上获得了身份验证。但这仅在我使用 drf 令牌身份验证(DEFAULT AUTH CLASSES)和授权令牌时有效以前在 django admin 上创建的用户。我错过了什么,以便我可以在没有 drf 令牌身份验证的情况下对用户进行身份验证?
views.py
config = {
"apiKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"authDomain": "xxxxx.firebaseapp.com",
"databaseURL": "https://xxxxxxxxx-default-rtdb.firebaseio.com",
"storageBucket": "xxxxxxxxx.appspot.com",
}
firebase = pyrebase.initialize_app(config)
auth = firebase.auth()
class Auth(APIView):
def post(self, request, format=None):
email = "xxxx@gmail.com"
password = "xxxx"
user = auth.sign_in_with_email_and_password(email, password)
return Response(user)
Settings.py
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework.authentication.TokenAuthentication",
),
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
}
【问题讨论】: