Skip to content

Commit

Permalink
feat: add sso
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Oct 29, 2023
1 parent 160b671 commit 1d5c286
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 @@ -246,6 +246,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(

Check warning on line 257 in gotrue/_async/gotrue_client.py

View check run for this annotation

Codecov / codecov/patch

gotrue/_async/gotrue_client.py#L250-L257

Added lines #L250 - L257 were not covered by tests
"POST",
"sso",
body={"domain": domain},
redirect_to=redirect_to,
xform=parse_auth_response,
)
if provider_id:
return await self._request(

Check warning on line 265 in gotrue/_async/gotrue_client.py

View check run for this annotation

Codecov / codecov/patch

gotrue/_async/gotrue_client.py#L264-L265

Added lines #L264 - L265 were not covered by tests
"POST" "sso",
body={"provider_id": provider_id},
redirect_to=redirect_to,
xform=parse_auth_response,
)
raise AuthInvalidCredentialsError(

Check warning on line 271 in gotrue/_async/gotrue_client.py

View check run for this annotation

Codecov / codecov/patch

gotrue/_async/gotrue_client.py#L271

Added line #L271 was not covered by tests
"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 @@ -246,6 +246,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(

Check warning on line 257 in gotrue/_sync/gotrue_client.py

View check run for this annotation

Codecov / codecov/patch

gotrue/_sync/gotrue_client.py#L250-L257

Added lines #L250 - L257 were not covered by tests
"POST",
"sso",
body={"domain": domain},
redirect_to=redirect_to,
xform=parse_auth_response,
)
if provider_id:
return self._request(

Check warning on line 265 in gotrue/_sync/gotrue_client.py

View check run for this annotation

Codecov / codecov/patch

gotrue/_sync/gotrue_client.py#L264-L265

Added lines #L264 - L265 were not covered by tests
"POST" "sso",
body={"provider_id": provider_id},
redirect_to=redirect_to,
xform=parse_auth_response,
)
raise AuthInvalidCredentialsError(

Check warning on line 271 in gotrue/_sync/gotrue_client.py

View check run for this annotation

Codecov / codecov/patch

gotrue/_sync/gotrue_client.py#L271

Added line #L271 was not covered by tests
"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 @@ -321,6 +321,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 1d5c286

Please sign in to comment.