|
22 | 22 | import time
|
23 | 23 |
|
24 | 24 | import firebase_admin
|
| 25 | +from firebase_admin import exceptions |
| 26 | +from firebase_admin import _auth_utils |
25 | 27 | from firebase_admin import _http_client
|
26 | 28 | from firebase_admin import _token_gen
|
27 | 29 | from firebase_admin import _user_import
|
|
30 | 32 |
|
31 | 33 |
|
32 | 34 | _AUTH_ATTRIBUTE = '_auth'
|
33 |
| -_ID_TOKEN_REVOKED = 'ID_TOKEN_REVOKED' |
34 |
| -_SESSION_COOKIE_REVOKED = 'SESSION_COOKIE_REVOKED' |
| 35 | +ID_TOKEN_REVOKED = 'ID_TOKEN_REVOKED' |
| 36 | +SESSION_COOKIE_REVOKED = 'SESSION_COOKIE_REVOKED' |
35 | 37 |
|
36 | 38 |
|
37 | 39 | __all__ = [
|
|
70 | 72 | ActionCodeSettings = _user_mgt.ActionCodeSettings
|
71 | 73 | ErrorInfo = _user_import.ErrorInfo
|
72 | 74 | ExportedUserRecord = _user_mgt.ExportedUserRecord
|
| 75 | +FirebaseAuthError = _auth_utils.FirebaseAuthError |
73 | 76 | ListUsersPage = _user_mgt.ListUsersPage
|
74 | 77 | UserImportHash = _user_import.UserImportHash
|
75 | 78 | ImportUserRecord = _user_import.ImportUserRecord
|
@@ -147,7 +150,7 @@ def verify_id_token(id_token, app=None, check_revoked=False):
|
147 | 150 | token_verifier = _get_auth_service(app).token_verifier
|
148 | 151 | verified_claims = token_verifier.verify_id_token(id_token)
|
149 | 152 | if check_revoked:
|
150 |
| - _check_jwt_revoked(verified_claims, _ID_TOKEN_REVOKED, 'ID token', app) |
| 153 | + _check_jwt_revoked(verified_claims, ID_TOKEN_REVOKED, 'ID token', app) |
151 | 154 | return verified_claims
|
152 | 155 |
|
153 | 156 | def create_session_cookie(id_token, expires_in, app=None):
|
@@ -196,7 +199,7 @@ def verify_session_cookie(session_cookie, check_revoked=False, app=None):
|
196 | 199 | token_verifier = _get_auth_service(app).token_verifier
|
197 | 200 | verified_claims = token_verifier.verify_session_cookie(session_cookie)
|
198 | 201 | if check_revoked:
|
199 |
| - _check_jwt_revoked(verified_claims, _SESSION_COOKIE_REVOKED, 'session cookie', app) |
| 202 | + _check_jwt_revoked(verified_claims, SESSION_COOKIE_REVOKED, 'session cookie', app) |
200 | 203 | return verified_claims
|
201 | 204 |
|
202 | 205 | def revoke_refresh_tokens(uid, app=None):
|
@@ -528,16 +531,10 @@ def generate_sign_in_with_email_link(email, action_code_settings, app=None):
|
528 | 531 | def _check_jwt_revoked(verified_claims, error_code, label, app):
|
529 | 532 | user = get_user(verified_claims.get('uid'), app=app)
|
530 | 533 | if verified_claims.get('iat') * 1000 < user.tokens_valid_after_timestamp:
|
531 |
| - raise AuthError(error_code, 'The Firebase {0} has been revoked.'.format(label)) |
532 |
| - |
533 |
| - |
534 |
| -class AuthError(Exception): |
535 |
| - """Represents an Exception encountered while invoking the Firebase auth API.""" |
536 |
| - |
537 |
| - def __init__(self, code, message, error=None): |
538 |
| - Exception.__init__(self, message) |
539 |
| - self.code = code |
540 |
| - self.detail = error |
| 534 | + raise FirebaseAuthError( |
| 535 | + exceptions.INVALID_ARGUMENT, |
| 536 | + 'The Firebase {0} has been revoked.'.format(label), |
| 537 | + auth_error_code=error_code) |
541 | 538 |
|
542 | 539 |
|
543 | 540 | class _AuthService(object):
|
|
0 commit comments