Skip to content

Commit

Permalink
feat: add sso
Browse files Browse the repository at this point in the history
  • Loading branch information
joel@joellee.org authored and joel committed Jan 17, 2024
1 parent 0d58002 commit 99c9409
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions gotrue/_async/gotrue_base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ async def _request(
)
response.raise_for_status()
result = response if no_resolve_json else response.json()
print(response)
if xform:
return xform(result)
except Exception as e:
Expand Down
26 changes: 26 additions & 0 deletions gotrue/_async/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,32 @@ async def sign_in_with_password(
self._notify_all_subscribers("SIGNED_IN", response.session)
return response

async def sign_in_with_sso(self, credentials: SignInWithSSOCredentials):
await self._remove_session()
provider_id = credentials.get("provider_id")
domain = credentials.get("domain")
options = credentials.get("options", {})
redirect_to = options.get("redirect_to")
captcha_token = options.get("captcha_token")
if domain:
return await self._request(
"POST",
"sso",
body={"domain": domain},
redirect_to=redirect_to,
xform=parse_auth_response,
)
if provider_id:
return await self._request(
"POST" "sso",
body={"provider_id": provider_id},
redirect_to=redirect_to,
xform=parse_auth_response,
)
raise AuthInvalidCredentialsError(
"You must provide either a domain or provider_id"
)

async def sign_in_with_oauth(
self,
credentials: SignInWithOAuthCredentials,
Expand Down
1 change: 1 addition & 0 deletions gotrue/_sync/gotrue_base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def _request(
)
response.raise_for_status()
result = response if no_resolve_json else response.json()
print(response)
if xform:
return xform(result)
except Exception as e:
Expand Down
26 changes: 26 additions & 0 deletions gotrue/_sync/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,32 @@ def sign_in_with_password(
self._notify_all_subscribers("SIGNED_IN", response.session)
return response

def sign_in_with_sso(self, credentials: SignInWithSSOCredentials):
self._remove_session()
provider_id = credentials.get("provider_id")
domain = credentials.get("domain")
options = credentials.get("options", {})
redirect_to = options.get("redirect_to")
captcha_token = options.get("captcha_token")
if domain:
return self._request(
"POST",
"sso",
body={"domain": domain},
redirect_to=redirect_to,
xform=parse_auth_response,
)
if provider_id:
return self._request(
"POST" "sso",
body={"provider_id": provider_id},
redirect_to=redirect_to,
xform=parse_auth_response,
)
raise AuthInvalidCredentialsError(
"You must provide either a domain or provider_id"
)

def sign_in_with_oauth(
self,
credentials: SignInWithOAuthCredentials,
Expand Down
11 changes: 11 additions & 0 deletions gotrue/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,17 @@ class SignInWithOAuthCredentials(TypedDict):
options: NotRequired[SignInWithOAuthCredentialsOptions]


class SignInWithSSOCredentials(TypedDict):
provider_id: NotRequired[str]
domain: NotRequired[str]
options: NotRequired[SignInWithSSOOptions]


class SignInWithSSOOptions(TypedDict):
redirect_to: NotRequired[str]
captcha_token: NotRequired[str]


class VerifyOtpParamsOptions(TypedDict):
redirect_to: NotRequired[str]
captcha_token: NotRequired[str]
Expand Down

0 comments on commit 99c9409

Please sign in to comment.