Skip to content

Commit

Permalink
feat: add new identity linking methods release in LWX (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
J0 committed Jan 28, 2024
2 parents c250f93 + 89bcd15 commit 96d18be
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
30 changes: 30 additions & 0 deletions gotrue/_async/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
AuthResponse,
CodeExchangeParams,
DecodedJWTDict,
IdentitiesResponse,
MFAChallengeAndVerifyParams,
MFAChallengeParams,
MFAEnrollParams,
Expand Down Expand Up @@ -332,6 +333,35 @@ async def sign_in_with_oauth(
url = await self._get_url_for_provider(provider, params)
return OAuthResponse(provider=provider, url=url)

async def link_identity(self, credentials):
provider = credentials.get("provider")
options = credentials.get("options", {})
redirect_to = options.get("redirect_to")
scopes = options.get("scopes")
params = options.get("query_params", {})
if redirect_to:
params["redirect_to"] = redirect_to
if scopes:
params["scopes"] = scopes
params["skip_browser_redirect"] = True

url = await self._get_url_for_provider(provider, params)
return OAuthResponse(provider=provider, url=url)

async def get_user_identities(self):
response = self.get_user()
return (
IdentitiesResponse(identities=response.user.identities)
if response.user
else AuthSessionMissingError()
)

async def unlink_identity(self, identity):
return await self._request(
"POST",
f"/user/identities/{identity.id}",
)

async def sign_in_with_otp(
self,
credentials: SignInWithPasswordlessCredentials,
Expand Down
30 changes: 30 additions & 0 deletions gotrue/_sync/gotrue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
AuthResponse,
CodeExchangeParams,
DecodedJWTDict,
IdentitiesResponse,
MFAChallengeAndVerifyParams,
MFAChallengeParams,
MFAEnrollParams,
Expand Down Expand Up @@ -332,6 +333,35 @@ def sign_in_with_oauth(
url = self._get_url_for_provider(provider, params)
return OAuthResponse(provider=provider, url=url)

def link_identity(self, credentials):
provider = credentials.get("provider")
options = credentials.get("options", {})
redirect_to = options.get("redirect_to")
scopes = options.get("scopes")
params = options.get("query_params", {})
if redirect_to:
params["redirect_to"] = redirect_to
if scopes:
params["scopes"] = scopes
params["skip_browser_redirect"] = True

url = self._get_url_for_provider(provider, params)
return OAuthResponse(provider=provider, url=url)

def get_user_identities(self):
response = self.get_user()
return (
IdentitiesResponse(identities=response.user.identities)
if response.user
else AuthSessionMissingError()
)

def unlink_identity(self, identity):
return self._request(
"POST",
f"/user/identities/{identity.id}",
)

def sign_in_with_otp(
self,
credentials: SignInWithPasswordlessCredentials,
Expand Down
4 changes: 4 additions & 0 deletions gotrue/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class SSOResponse(BaseModel):
url: str


class IdentitiesResponse(BaseModel):
identities: List[UserIdentity]


class UserResponse(BaseModel):
user: User

Expand Down

0 comments on commit 96d18be

Please sign in to comment.