Skip to content

Commit

Permalink
Add AuthenticationResponse and PasswordChallengeResponse to UserManag…
Browse files Browse the repository at this point in the history
…ement resources
  • Loading branch information
blairworkos committed Nov 20, 2023
1 parent a430489 commit f8d1b1e
Showing 4 changed files with 73 additions and 74 deletions.
27 changes: 0 additions & 27 deletions workos/resources/authentication_response.py

This file was deleted.

32 changes: 0 additions & 32 deletions workos/resources/password_challenge_response.py

This file was deleted.

79 changes: 67 additions & 12 deletions workos/resources/user_management.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,90 @@
from workos.resources.base import WorkOSBaseResource


class WorkOSUser(WorkOSBaseResource):
"""Representation of a User as returned by WorkOS through User Management features.
class WorkOSAuthenticationResponse(WorkOSBaseResource):
"""Representation of a User and Session response as returned by WorkOS through User Management features."""

@classmethod
def construct_from_response(cls, response):
authentication_response = super(
WorkOSAuthenticationResponse, cls
).construct_from_response(response)

user = WorkOSUser.construct_from_response(response["user"])
authentication_response.user = user

return authentication_response

def to_dict(self):
authentication_response_dict = super(
WorkOSAuthenticationResponse, self
).to_dict()

user_dict = self.user.to_dict()
authentication_response_dict["user"] = user_dict

return authentication_response_dict


class WorkOSOrganizationMembership(WorkOSBaseResource):
"""Representation of an Organization Membership as returned by WorkOS through User Management features.
Attributes:
OBJECT_FIELDS (list): List of fields a WorkOSUser comprises.
OBJECT_FIELDS (list): List of fields a WorkOSOrganizationMembership comprises.
"""

OBJECT_FIELDS = [
"id",
"email",
"first_name",
"last_name",
"email_verified",
"user_id",
"organization_id",
"created_at",
"updated_at",
]


class WorkOSOrganizationMembership(WorkOSBaseResource):
"""Representation of an Organization Membership as returned by WorkOS through User Management features.
class WorkOSPasswordChallengeResponse(WorkOSBaseResource):
"""Representation of a User and token response as returned by WorkOS through User Management features.
Attributes:
OBJECT_FIELDS (list): List of fields a WorkOSPasswordChallengeResponse is comprised of.
"""

OBJECT_FIELDS = [
"token",
]

@classmethod
def construct_from_response(cls, response):
challenge_response = super(
WorkOSPasswordChallengeResponse, cls
).construct_from_response(response)

user = WorkOSUser.construct_from_response(response["user"])
challenge_response.user = user

return challenge_response

def to_dict(self):
challenge_response = super(WorkOSPasswordChallengeResponse, self).to_dict()

user_dict = self.user.to_dict()
challenge_response["user"] = user_dict

return challenge_response


class WorkOSUser(WorkOSBaseResource):
"""Representation of a User as returned by WorkOS through User Management features.
Attributes:
OBJECT_FIELDS (list): List of fields a WorkOSOrganizationMembership comprises.
OBJECT_FIELDS (list): List of fields a WorkOSUser comprises.
"""

OBJECT_FIELDS = [
"id",
"user_id",
"organization_id",
"email",
"first_name",
"last_name",
"email_verified",
"created_at",
"updated_at",
]
9 changes: 6 additions & 3 deletions workos/user_management.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import workos
from workos.resources.authentication_response import WorkOSAuthenticationResponse
from workos.resources.password_challenge_response import WorkOSPasswordChallengeResponse
from workos.resources.list import WorkOSListResource
from workos.resources.mfa import WorkOSAuthenticationFactorTotp, WorkOSChallenge
from workos.resources.user_management import WorkOSUser, WorkOSOrganizationMembership
from workos.resources.user_management import (
WorkOSAuthenticationResponse,
WorkOSOrganizationMembership,
WorkOSPasswordChallengeResponse,
WorkOSUser,
)
from workos.utils.pagination_order import Order
from workos.utils.request import (
RequestHelper,

0 comments on commit f8d1b1e

Please sign in to comment.