Skip to content

Commit 0fda6ae

Browse files
authored
Add AuthBase class (#179)
1 parent 0c11846 commit 0fda6ae

File tree

18 files changed

+44
-116
lines changed

18 files changed

+44
-116
lines changed

descope/_auth_base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This is not part of the public API but a code helper
2+
from descope.auth import Auth
3+
4+
5+
class AuthBase:
6+
"""Base class for classes having auth"""
7+
8+
def __init__(self, auth: Auth):
9+
self._auth = auth

descope/authmethod/enchantedlink.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import requests
44

5+
from descope._auth_base import AuthBase
56
from descope.auth import Auth
67
from descope.common import (
78
REFRESH_SESSION_COOKIE_NAME,
@@ -13,12 +14,7 @@
1314
from descope.exceptions import ERROR_TYPE_INVALID_ARGUMENT, AuthException
1415

1516

16-
class EnchantedLink:
17-
_auth: Auth
18-
19-
def __init__(self, auth: Auth):
20-
self._auth = auth
21-
17+
class EnchantedLink(AuthBase):
2218
def sign_in(
2319
self,
2420
login_id: str,

descope/authmethod/magiclink.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import string
22

3+
from descope._auth_base import AuthBase
34
from descope.auth import Auth
45
from descope.common import (
56
REFRESH_SESSION_COOKIE_NAME,
@@ -11,12 +12,7 @@
1112
from descope.exceptions import ERROR_TYPE_INVALID_ARGUMENT, AuthException
1213

1314

14-
class MagicLink:
15-
_auth: Auth
16-
17-
def __init__(self, auth: Auth):
18-
self._auth = auth
19-
15+
class MagicLink(AuthBase):
2016
def sign_in(
2117
self,
2218
method: DeliveryMethod,

descope/authmethod/oauth.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
from descope.auth import Auth
1+
from descope._auth_base import AuthBase
22
from descope.common import EndpointsV1, LoginOptions, validate_refresh_token_provided
33
from descope.exceptions import ERROR_TYPE_INVALID_ARGUMENT, AuthException
44

55

6-
class OAuth:
7-
_auth: Auth
8-
9-
def __init__(self, auth: Auth):
10-
self._auth = auth
11-
6+
class OAuth(AuthBase):
127
def start(
138
self,
149
provider: str,

descope/authmethod/otp.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from descope._auth_base import AuthBase
12
from descope.auth import Auth
23
from descope.common import (
34
REFRESH_SESSION_COOKIE_NAME,
@@ -9,12 +10,7 @@
910
from descope.exceptions import ERROR_TYPE_INVALID_ARGUMENT, AuthException
1011

1112

12-
class OTP:
13-
_auth: Auth
14-
15-
def __init__(self, auth: Auth):
16-
self._auth = auth
17-
13+
class OTP(AuthBase):
1814
def sign_in(
1915
self,
2016
method: DeliveryMethod,

descope/authmethod/password.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
from descope.auth import Auth
1+
from descope._auth_base import AuthBase
22
from descope.common import REFRESH_SESSION_COOKIE_NAME, EndpointsV1
33
from descope.exceptions import ERROR_TYPE_INVALID_ARGUMENT, AuthException
44

55

6-
class Password:
7-
_auth: Auth
8-
9-
def __init__(self, auth):
10-
self._auth = auth
11-
6+
class Password(AuthBase):
127
def sign_up(self, login_id: str, password: str, user: dict = None) -> dict:
138
"""
149
Sign up (create) a new user using a login ID and password.

descope/authmethod/saml.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
from descope.auth import Auth
1+
from descope._auth_base import AuthBase
22
from descope.common import EndpointsV1, LoginOptions, validate_refresh_token_provided
33
from descope.exceptions import ERROR_TYPE_INVALID_ARGUMENT, AuthException
44

55

6-
class SAML:
7-
_auth: Auth
8-
9-
def __init__(self, auth: Auth):
10-
self._auth = auth
11-
6+
class SAML(AuthBase):
127
def start(
138
self,
149
tenant: str,

descope/authmethod/totp.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from descope.auth import Auth
1+
from descope._auth_base import AuthBase
22
from descope.common import (
33
REFRESH_SESSION_COOKIE_NAME,
44
EndpointsV1,
@@ -8,20 +8,15 @@
88
from descope.exceptions import ERROR_TYPE_INVALID_ARGUMENT, AuthException
99

1010

11-
class TOTP:
12-
_auth: Auth
13-
14-
def __init__(self, auth):
15-
self._auth = auth
16-
11+
class TOTP(AuthBase):
1712
def sign_up(self, login_id: str, user: dict = None) -> dict:
1813
"""
1914
Sign up (create) a new user using their email or phone number.
2015
(optional) Include additional user metadata that you wish to save.
2116
2217
Args:
2318
login_id (str): The login ID of the user being validated
24-
user (dict) optional: Preserve additional user metadata in the form of
19+
user (dict) optional: Preserve additional user metadata in the form of,
2520
{"name": "Desmond Copeland", "phone": "2125551212", "email": "[email protected]"}
2621
2722
Return value (dict):

descope/authmethod/webauthn.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from descope.auth import Auth
1+
from descope._auth_base import AuthBase
22
from descope.common import (
33
REFRESH_SESSION_COOKIE_NAME,
44
EndpointsV1,
@@ -8,12 +8,7 @@
88
from descope.exceptions import ERROR_TYPE_INVALID_ARGUMENT, AuthException
99

1010

11-
class WebAuthn:
12-
_auth: Auth
13-
14-
def __init__(self, auth):
15-
self._auth = auth
16-
11+
class WebAuthn(AuthBase):
1712
def sign_up_start(self, login_id: str, origin: str, user: dict = None) -> dict:
1813
"""
1914
Docs

descope/management/access_key.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
from typing import List
22

3-
from descope.auth import Auth
3+
from descope._auth_base import AuthBase
44
from descope.management.common import (
55
AssociatedTenant,
66
MgmtV1,
77
associated_tenants_to_dict,
88
)
99

1010

11-
class AccessKey:
12-
_auth: Auth
13-
14-
def __init__(self, auth: Auth):
15-
self._auth = auth
16-
11+
class AccessKey(AuthBase):
1712
def create(
1813
self,
1914
name: str,

0 commit comments

Comments
 (0)