Skip to content

Commit b7e2c2c

Browse files
authored
feat: add sign_in_with_id_token method (#548)
1 parent 79a24f0 commit b7e2c2c

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

supabase_auth/_async/gotrue_client.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
Provider,
6464
Session,
6565
SignInAnonymouslyCredentials,
66+
SignInWithIdTokenCredentials,
6667
SignInWithOAuthCredentials,
6768
SignInWithPasswordCredentials,
6869
SignInWithPasswordlessCredentials,
@@ -293,6 +294,44 @@ async def sign_in_with_password(
293294
self._notify_all_subscribers("SIGNED_IN", response.session)
294295
return response
295296

297+
async def sign_in_with_id_token(
298+
self,
299+
credentials: SignInWithIdTokenCredentials,
300+
) -> AuthResponse:
301+
"""
302+
Allows signing in with an OIDC ID token. The authentication provider used should be enabled and configured.
303+
"""
304+
await self._remove_session()
305+
provider = credentials.get("provider")
306+
token = credentials.get("token")
307+
access_token = credentials.get("access_token")
308+
nonce = credentials.get("nonce")
309+
options = credentials.get("options", {})
310+
captcha_token = options.get("captcha_token")
311+
312+
response = await self._request(
313+
"POST",
314+
"token",
315+
body={
316+
"provider": provider,
317+
"id_token": token,
318+
"access_token": access_token,
319+
"nonce": nonce,
320+
"gotrue_meta_security": {
321+
"captcha_token": captcha_token,
322+
},
323+
},
324+
query={
325+
"grant_type": "id_token",
326+
},
327+
xform=parse_auth_response,
328+
)
329+
330+
if response.session:
331+
await self._save_session(response.session)
332+
self._notify_all_subscribers("SIGNED_IN", response.session)
333+
return response
334+
296335
async def sign_in_with_sso(self, credentials: SignInWithSSOCredentials):
297336
"""
298337
Attempts a single-sign on using an enterprise Identity Provider. A

supabase_auth/_sync/gotrue_client.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
Provider,
6464
Session,
6565
SignInAnonymouslyCredentials,
66+
SignInWithIdTokenCredentials,
6667
SignInWithOAuthCredentials,
6768
SignInWithPasswordCredentials,
6869
SignInWithPasswordlessCredentials,
@@ -293,6 +294,44 @@ def sign_in_with_password(
293294
self._notify_all_subscribers("SIGNED_IN", response.session)
294295
return response
295296

297+
def sign_in_with_id_token(
298+
self,
299+
credentials: SignInWithIdTokenCredentials,
300+
) -> AuthResponse:
301+
"""
302+
Allows signing in with an OIDC ID token. The authentication provider used should be enabled and configured.
303+
"""
304+
self._remove_session()
305+
provider = credentials.get("provider")
306+
token = credentials.get("token")
307+
access_token = credentials.get("access_token")
308+
nonce = credentials.get("nonce")
309+
options = credentials.get("options", {})
310+
captcha_token = options.get("captcha_token")
311+
312+
response = self._request(
313+
"POST",
314+
"token",
315+
body={
316+
"provider": provider,
317+
"id_token": token,
318+
"access_token": access_token,
319+
"nonce": nonce,
320+
"gotrue_meta_security": {
321+
"captcha_token": captcha_token,
322+
},
323+
},
324+
query={
325+
"grant_type": "id_token",
326+
},
327+
xform=parse_auth_response,
328+
)
329+
330+
if response.session:
331+
self._save_session(response.session)
332+
self._notify_all_subscribers("SIGNED_IN", response.session)
333+
return response
334+
296335
def sign_in_with_sso(self, credentials: SignInWithSSOCredentials):
297336
"""
298337
Attempts a single-sign on using an enterprise Identity Provider. A

supabase_auth/types.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,22 @@ class SignInWithPhoneAndPasswordCredentials(TypedDict):
303303
]
304304

305305

306+
class SignInWithIdTokenCredentials(TypedDict):
307+
"""
308+
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).
309+
"""
310+
311+
provider: Literal["google", "apple", "azure", "facebook", "kakao"]
312+
token: str
313+
access_token: NotRequired[str]
314+
nonce: NotRequired[str]
315+
options: NotRequired[SignInWithIdTokenCredentialsOptions]
316+
317+
318+
class SignInWithIdTokenCredentialsOptions(TypedDict):
319+
captcha_token: NotRequired[str]
320+
321+
306322
class SignInWithEmailAndPasswordlessCredentialsOptions(TypedDict):
307323
email_redirect_to: NotRequired[str]
308324
should_create_user: NotRequired[bool]

0 commit comments

Comments
 (0)