Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added create_user_pool_client #279

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pycognito/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,24 @@ def admin_update_identity_provider(self, pool_id, provider_name, **kwargs):
**kwargs,
)

def create_user_pool_client(self, client_name, pool_id=None, **kwargs):
"""
Creates a user pool client
:param client_name: The name of the user pool client
:param pool_id: The user pool ID (defaults to self.user_pool_id)
:param kwargs: Additional User Pool Client parameters
:return response: UserPoolClient response from Cognito
"""
if pool_id is None:
pool_id = self.user_pool_id

response = self.client.create_user_pool_client(
UserPoolId=pool_id,
ClientName=client_name,
**kwargs,
)
return response["UserPoolClient"]

def describe_user_pool_client(self, pool_id: str, client_id: str):
"""
Returns configuration information of a specified user pool app client
Expand Down
57 changes: 57 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,5 +496,62 @@ def test_srp_requests_http_auth(self, m):
self.assertNotEqual(access_token_orig, access_token_new)


@moto.mock_aws
class CognitoUserPoolClientTestCase(unittest.TestCase):
client_name = "test-client"

def setUp(self) -> None:

self.cognito_idp = boto3.client("cognito-idp", region_name="us-east-1")

user_pool = self.cognito_idp.create_user_pool(
PoolName="pycognito-test-pool",
AliasAttributes=[
"email",
],
UsernameAttributes=[
"email",
],
)
self.user_pool_id = user_pool["UserPool"]["Id"]

self.params = {
"RefreshTokenValidity": 1,
"AccessTokenValidity": 1,
"IdTokenValidity": 1,
"TokenValidityUnits": {
"AccessToken": "hour",
"IdToken": "hour",
"RefreshToken": "days",
},
}

def test_create_user_pool_client(self):
cognito = Cognito(user_pool_id=self.user_pool_id, client_id=None)
response = cognito.create_user_pool_client(
client_name=self.client_name, **self.params
)

self.assertEqual(response["ClientName"], self.client_name)
self.assertEqual(response["AccessTokenValidity"], 1)

def test_describe_user_pool_client(self):
params = self.params.copy()
params.update({"UserPoolId": self.user_pool_id})
params.update({"ClientName": self.client_name})

response = self.cognito_idp.create_user_pool_client(**params)

client_id = response["UserPoolClient"]["ClientId"]
cognito = Cognito(user_pool_id=self.user_pool_id, client_id=client_id)
response = cognito.describe_user_pool_client(
pool_id=self.user_pool_id, client_id=client_id
)

self.assertEqual(response["UserPoolId"], self.user_pool_id)
self.assertEqual(response["ClientId"], client_id)
self.assertEqual(response["ClientName"], self.client_name)


if __name__ == "__main__":
unittest.main()