-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add number verification to network auth
- Loading branch information
Showing
15 changed files
with
298 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.1.1b0' | ||
__version__ = '1.0.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class CreateOidcUrl(BaseModel): | ||
"""Model to craft a URL for OIDC authentication. | ||
Args: | ||
redirect_uri (str): The URI to redirect to after authentication. | ||
state (str): A unique identifier for the request. Can be any string. | ||
login_hint (str): The phone number to use for the request. | ||
""" | ||
|
||
redirect_uri: str | ||
state: str | ||
login_hint: str | ||
scope: Optional[ | ||
str | ||
] = 'openid dpv:FraudPreventionAndDetection#number-verification-verify-read' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 11 additions & 2 deletions
13
network_number_verification/src/vonage_network_number_verification/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
from .number_verification import NetworkNumberVerification | ||
from .errors import NetworkNumberVerificationError | ||
from .number_verification import CreateOidcUrl, NetworkNumberVerification | ||
from .requests import NumberVerificationRequest | ||
from .responses import NumberVerificationResponse | ||
|
||
__all__ = ['NetworkNumberVerification'] | ||
__all__ = [ | ||
'NetworkNumberVerification', | ||
'CreateOidcUrl', | ||
'NumberVerificationRequest', | ||
'NumberVerificationResponse', | ||
'NetworkNumberVerificationError', | ||
] |
5 changes: 5 additions & 0 deletions
5
network_number_verification/src/vonage_network_number_verification/errors.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from vonage_utils import VonageError | ||
|
||
|
||
class NetworkNumberVerificationError(VonageError): | ||
"""Base class for Vonage Network Number Verification errors.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 23 additions & 22 deletions
45
network_number_verification/src/vonage_network_number_verification/requests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class CreateOidcUrl(BaseModel): | ||
"""Model to craft a URL for OIDC authentication. | ||
Args: | ||
redirect_uri (str): The URI to redirect to after authentication. | ||
state (str, optional): A unique identifier for the request. Can be any string. | ||
login_hint (str, optional): The phone number to use for the request. | ||
""" | ||
|
||
redirect_uri: str | ||
state: Optional[str] = None | ||
login_hint: Optional[str] = None | ||
scope: Optional[ | ||
str | ||
] = 'openid dpv:FraudPreventionAndDetection#number-verification-verify-read' | ||
from pydantic import BaseModel, Field, model_validator | ||
from vonage_network_number_verification.errors import NetworkNumberVerificationError | ||
|
||
|
||
class NumberVerificationRequest(BaseModel): | ||
"""Model for the request to verify a phone number. | ||
Args: | ||
access_token (str): The access token for the request obtained from the | ||
three-legged OAuth2 flow. | ||
phone_number (str): The phone number to verify. Use the E.164 format with | ||
or without a leading +. | ||
hashed_phone_number (str): The hashed phone number to verify. | ||
""" | ||
|
||
phone_number: str = Field(..., alias='phoneNumber') | ||
hashed_phone_number: str = Field(..., alias='hashedPhoneNumber') | ||
access_token: str | ||
phone_number: str = Field(None, serialization_alias='phoneNumber') | ||
hashed_phone_number: str = Field(None, serialization_alias='hashedPhoneNumber') | ||
|
||
@model_validator(mode='after') | ||
def check_only_one_phone_number(self): | ||
"""Check that only one of `phone_number` and `hashed_phone_number` is set.""" | ||
|
||
if self.phone_number is not None and self.hashed_phone_number is not None: | ||
raise NetworkNumberVerificationError( | ||
'Only one of `phone_number` and `hashed_phone_number` can be set.' | ||
) | ||
|
||
if self.phone_number is None and self.hashed_phone_number is None: | ||
raise NetworkNumberVerificationError( | ||
'One of `phone_number` and `hashed_phone_number` must be set.' | ||
) | ||
|
||
return self |
Oops, something went wrong.