Skip to content

Commit 240ef7c

Browse files
fix(auth): create_custom_token
The issue arose when updating dependencies
1 parent b34902c commit 240ef7c

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

firebase/auth/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import python_jwt as jwt
1818
import jwcrypto.jwk as jwk
1919
from urllib.parse import parse_qs
20+
from cryptography.hazmat.primitives.serialization import Encoding, NoEncryption, PrivateFormat
2021

2122
from firebase._exception import raise_detailed_error
2223

@@ -190,7 +191,7 @@ def create_custom_token(self, uid, additional_claims=None, expiry_minutes=60):
190191
"""
191192

192193
service_account_email = self.credentials.service_account_email
193-
private_key = jwk.JWK.from_pem(self.credentials._private_key_pkcs8_pem.encode('utf-8'))
194+
private_key = jwk.JWK.from_pem(self.credentials.signer._key.private_bytes(encoding=Encoding.PEM, format=PrivateFormat.PKCS8, encryption_algorithm=NoEncryption()))
194195

195196
payload = {
196197
"iss": service_account_email,
@@ -204,7 +205,7 @@ def create_custom_token(self, uid, additional_claims=None, expiry_minutes=60):
204205

205206
exp = datetime.timedelta(minutes=expiry_minutes)
206207

207-
return jwt.generate_jwt(payload, private_key, "RS256", exp, other_headers={'kid': self.credentials._private_key_id})
208+
return jwt.generate_jwt(payload, private_key, "RS256", exp, other_headers={'kid': self.credentials.signer._key_id})
208209

209210
def sign_in_with_custom_token(self, token):
210211
""" Exchange custom token for an ID and refresh token.

tests/test_auth.py

-6
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,16 @@ def test_sign_in_anonymous(self, auth_admin):
118118
self.__class__.anonymous_user = user
119119
assert user
120120

121-
@pytest.mark.xfail
122121
def test_create_custom_token(self, auth_admin):
123122
token = auth_admin.create_custom_token('CreateCustomToken1')
124123
self.__class__.custom_token = token
125124
assert token
126125

127-
@pytest.mark.xfail
128126
def test_create_custom_token_with_claims(self, auth_admin):
129127
token = auth_admin.create_custom_token('CreateCustomToken2', {'premium': True})
130128
self.__class__.custom_token_with_claims = token
131129
assert token
132130

133-
@pytest.mark.xfail
134131
def test_sign_in_with_custom_token(self, auth_admin):
135132
user1 = auth_admin.sign_in_with_custom_token(self.__class__.custom_token)
136133
user2 = auth_admin.sign_in_with_custom_token(self.__class__.custom_token_with_claims)
@@ -166,8 +163,5 @@ def test_update_profile_display_name(self, auth_admin):
166163
def test_delete_user_account(self, auth_admin):
167164
assert auth_admin.delete_user_account(self.__class__.user.get('idToken'))
168165
assert auth_admin.delete_user_account(self.__class__.anonymous_user.get('idToken'))
169-
170-
@pytest.mark.xfail
171-
def test_delete_custom_user_account(self, auth_admin):
172166
assert auth_admin.delete_user_account(self.__class__.custom_user.get('idToken'))
173167
assert auth_admin.delete_user_account(self.__class__.custom_user_with_claims.get('idToken'))

0 commit comments

Comments
 (0)