Skip to content

Commit

Permalink
Fix merge conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgd committed Jul 30, 2024
2 parents 205aed4 + 06f4360 commit bc7b267
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/test_user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ def test_authenticate_with_refresh_token(
assert request_kwargs["json"] == {
**params,
**base_authentication_params,
"organization_id": None,
"grant_type": "refresh_token",
}

Expand Down
30 changes: 30 additions & 0 deletions tests/utils/fixtures/mock_directory_activated_payload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import datetime
from workos.resources.base import WorkOSBaseResource


class MockDirectoryActivatedPayload(WorkOSBaseResource):
def __init__(self, id):
now = datetime.datetime.now().isoformat()
self.object = "directory"
self.id = id
self.organization_id = "organization_id"
self.external_key = "ext_123"
self.domains = []
self.name = "Some fake name"
self.state = "active"
self.type = "gsuite directory"
self.created_at = now
self.updated_at = now

OBJECT_FIELDS = [
"object",
"id",
"name",
"external_key",
"domains",
"organization_id",
"state",
"type",
"created_at",
"updated_at",
]
2 changes: 1 addition & 1 deletion workos/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

__package_url__ = "https://github.com/workos-inc/workos-python"

__version__ = "4.12.0"
__version__ = "4.13.0"

__author__ = "WorkOS"

Expand Down
39 changes: 39 additions & 0 deletions workos/resources/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from typing import List


class WorkOSBaseResource(object):
"""Representation of a WorkOS Resource as returned through the API.
Attributes:
OBJECT_FIELDS (list): List of fields a Resource is comprised of.
"""

OBJECT_FIELDS: List[str] = []

@classmethod
def construct_from_response(cls, response):
"""Returns an instance of WorkOSBaseResource.
Args:
response (dict): Resource data from a WorkOS API response
Returns:
WorkOSBaseResource: Instance of a WorkOSBaseResource with OBJECT_FIELDS fields set
"""
obj = cls()
for field in cls.OBJECT_FIELDS:
setattr(obj, field, response.get(field))

return obj

def to_dict(self):
"""Returns a dict representation of the WorkOSBaseResource.
Returns:
dict: A dict representation of the WorkOSBaseResource
"""
obj_dict = {}
for field in self.OBJECT_FIELDS:
obj_dict[field] = getattr(self, field, None)

return obj_dict
4 changes: 4 additions & 0 deletions workos/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def authenticate_with_organization_selection(
def authenticate_with_refresh_token(
self,
refresh_token: str,
organization_id: Optional[str] = None,
ip_address: Optional[str] = None,
user_agent: Optional[str] = None,
) -> RefreshTokenAuthenticationResponse: ...
Expand Down Expand Up @@ -927,13 +928,15 @@ def authenticate_with_organization_selection(
def authenticate_with_refresh_token(
self,
refresh_token: str,
organization_id: Optional[str] = None,
ip_address: Optional[str] = None,
user_agent: Optional[str] = None,
) -> RefreshTokenAuthenticationResponse:
"""Authenticates a user with a refresh token.
Kwargs:
refresh_token (str): The token associated to the user.
organization_id (str): The organization to issue the new access token for. (Optional)
ip_address (str): The IP address of the request from the user who is attempting to authenticate. (Optional)
user_agent (str): The user agent of the request from the user who is attempting to authenticate. (Optional)
Expand All @@ -945,6 +948,7 @@ def authenticate_with_refresh_token(
"client_id": workos.client_id,
"client_secret": workos.api_key,
"refresh_token": refresh_token,
"organization_id": organization_id,
"grant_type": "refresh_token",
"ip_address": ip_address,
"user_agent": user_agent,
Expand Down

0 comments on commit bc7b267

Please sign in to comment.