Skip to content

Commit 67edfbb

Browse files
committed
a bit of refactoring + some more documentation
1 parent 67c7af3 commit 67edfbb

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/posit/connect/oauth/oauth.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def __init__(self, params: ResourceParameters, api_key: str) -> None:
3636
super().__init__(params)
3737
self.api_key = api_key
3838

39+
def _get_credentials_url(self) -> str:
40+
return self.params.url + "v1/oauth/integrations/credentials"
41+
3942
@property
4043
def integrations(self):
4144
return Integrations(self.params)
@@ -45,7 +48,7 @@ def sessions(self):
4548
return Sessions(self.params)
4649

4750
def get_credentials(self, user_session_token: Optional[str] = None) -> Credentials:
48-
url = self.params.url + "v1/oauth/integrations/credentials"
51+
"""Perform an oauth credential exchange for a viewer's access token."""
4952

5053
# craft a credential exchange request
5154
data = {}
@@ -54,19 +57,19 @@ def get_credentials(self, user_session_token: Optional[str] = None) -> Credentia
5457
if user_session_token:
5558
data["subject_token"] = user_session_token
5659

57-
response = self.params.session.post(url, data=data)
60+
response = self.params.session.post(self._get_credentials_url(), data=data)
5861
return Credentials(**response.json())
5962

6063
def get_content_credentials(self, content_session_token: Optional[str] = None) -> Credentials:
61-
url = self.params.url + "v1/oauth/integrations/credentials"
62-
64+
"""Perform an oauth credential exchange for a service account's access token."""
65+
6366
# craft a credential exchange request
6467
data = {}
6568
data["grant_type"] = GRANT_TYPE
6669
data["subject_token_type"] = CONTENT_SESSION_TOKEN_TYPE
6770
data["subject_token"] = content_session_token or _get_content_session_token()
6871

69-
response = self.params.session.post(url, data=data)
72+
response = self.params.session.post(self._get_credentials_url(), data=data)
7073
return Credentials(**response.json())
7174

7275
class Credentials(TypedDict, total=False):

0 commit comments

Comments
 (0)