Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sign_in_with_id_token method #548

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions supabase_auth/_async/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
Provider,
Session,
SignInAnonymouslyCredentials,
SignInWithIdTokenCredentials,
SignInWithOAuthCredentials,
SignInWithPasswordCredentials,
SignInWithPasswordlessCredentials,
Expand Down Expand Up @@ -293,6 +294,44 @@ async def sign_in_with_password(
self._notify_all_subscribers("SIGNED_IN", response.session)
return response

async def sign_in_with_id_token(
self,
credentials: SignInWithIdTokenCredentials,
) -> AuthResponse:
"""
Allows signing in with an OIDC ID token. The authentication provider used should be enabled and configured.
"""
await self._remove_session()
provider = credentials.get("provider")
token = credentials.get("token")
access_token = credentials.get("access_token")
nonce = credentials.get("nonce")
options = credentials.get("options", {})
captcha_token = options.get("captcha_token")

response = await self._request(
"POST",
"token",
body={
"provider": provider,
"id_token": token,
"access_token": access_token,
"nonce": nonce,
"gotrue_meta_security": {
"captcha_token": captcha_token,
},
},
query={
"grant_type": "id_token",
},
xform=parse_auth_response,
)

if response.session:
await self._save_session(response.session)
self._notify_all_subscribers("SIGNED_IN", response.session)
return response

async def sign_in_with_sso(self, credentials: SignInWithSSOCredentials):
"""
Attempts a single-sign on using an enterprise Identity Provider. A
Expand Down
39 changes: 39 additions & 0 deletions supabase_auth/_sync/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
Provider,
Session,
SignInAnonymouslyCredentials,
SignInWithIdTokenCredentials,
SignInWithOAuthCredentials,
SignInWithPasswordCredentials,
SignInWithPasswordlessCredentials,
Expand Down Expand Up @@ -293,6 +294,44 @@ def sign_in_with_password(
self._notify_all_subscribers("SIGNED_IN", response.session)
return response

def sign_in_with_id_token(
self,
credentials: SignInWithIdTokenCredentials,
) -> AuthResponse:
"""
Allows signing in with an OIDC ID token. The authentication provider used should be enabled and configured.
"""
self._remove_session()
provider = credentials.get("provider")
token = credentials.get("token")
access_token = credentials.get("access_token")
nonce = credentials.get("nonce")
options = credentials.get("options", {})
captcha_token = options.get("captcha_token")

response = self._request(
"POST",
"token",
body={
"provider": provider,
"id_token": token,
"access_token": access_token,
"nonce": nonce,
"gotrue_meta_security": {
"captcha_token": captcha_token,
},
},
query={
"grant_type": "id_token",
},
xform=parse_auth_response,
)

if response.session:
self._save_session(response.session)
self._notify_all_subscribers("SIGNED_IN", response.session)
return response

def sign_in_with_sso(self, credentials: SignInWithSSOCredentials):
"""
Attempts a single-sign on using an enterprise Identity Provider. A
Expand Down
16 changes: 16 additions & 0 deletions supabase_auth/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,22 @@ class SignInWithPhoneAndPasswordCredentials(TypedDict):
]


class SignInWithIdTokenCredentials(TypedDict):
"""
Provider name or OIDC `iss` value identifying which provider should be used to verify the provided token. Supported names: `google`, `apple`, `azure`, `facebook`, `kakao`, `keycloak` (deprecated).
"""

provider: Literal["google", "apple", "azure", "facebook", "kakao"]
token: str
access_token: NotRequired[str]
nonce: NotRequired[str]
options: NotRequired[SignInWithIdTokenCredentialsOptions]


class SignInWithIdTokenCredentialsOptions(TypedDict):
captcha_token: NotRequired[str]


class SignInWithEmailAndPasswordlessCredentialsOptions(TypedDict):
email_redirect_to: NotRequired[str]
should_create_user: NotRequired[bool]
Expand Down
Loading