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

feat: add third party integrations #577

Merged
merged 11 commits into from
Feb 23, 2023
Merged

feat: add third party integrations #577

merged 11 commits into from
Feb 23, 2023

Conversation

lfleischmann
Copy link
Member

@lfleischmann lfleischmann commented Feb 14, 2023

Description

Adds support for OAuth-based social/third party login. First supported providers are Google and GitHub only.

Implementation

  • New thirdparty/auth API endpoint which redirects to the third party provider.
    • Provider implementations build authorization code endpoint URL for the respective provider and redirect.
  • New thirdparty/callback API endpoint, which is called by the third party provider with an authorization code (or an error).
    • Provider implementations exchange the authorization code for an access token and use this access token to retrieve user data.
  • Provider user data is then used in the main logic ( linking.go) for determining whether an account has to be created with Hanko and linked to a provider. Third party provider account links are persisted as identities that are in turn linked to an email address. Main requirements for the linking logic were:
    • Do not allow third party provider sign-in for third party account with the same email as an existing account.
    • When an email that is linked to a third party account is deleted, also delete the identity (because otherwise the user could sign in using the third party provider, but not use the "regular" Hanko login with said email) - this is currently solved through a delete cascade on the email FK constraint in the identity schema. Drawback is that we lose possibility for more granular audit logs: when you delete an email, audit logs will tell you just that, but not that an identity was removed.
    • When a user updates her primary mail with the third party provider and that email does not exist yet with Hanko, the email will be created and linked to the third party account.

Tests

I could not get a grasp on how to use our "fake" persistence layer to properly test a majority (i.e. the "linking") of the code. This "fake" layer does not accurately mimic what our real DB layer does. More specifically: it cannot fetch associations (unless they are refactored/rebuilt such that they can - I tried that, I gave up).

How to test

  • Follow the guides in the docs, i.e. create client app + credentials with the respective provider, configure the backend, run quickstart

Additional context

  • Because identities are linked to an email address, an identity can potentially be linked to an unassigned email address.
  • Only one third party account can be currently linked to an email.
  • No E2E tests

@lfleischmann lfleischmann marked this pull request as ready for review February 14, 2023 11:41
frontend/frontend-sdk/src/lib/Dto.ts Outdated Show resolved Hide resolved
frontend/frontend-sdk/src/index.ts Outdated Show resolved Hide resolved
frontend/elements/src/Translations.ts Outdated Show resolved Hide resolved
@bjoern-m
Copy link
Contributor

Currently the new third party sign in buttons don't have a loading state. When I click one of them it takes a while on my end before I get redirected (~3 sec). Would suggest to add a loading state, because I think it would feel a bit more dynamic. Also the other input elements should be disabled.

Co-authored-by: bjoern-m <56024829+bjoern-m@users.noreply.github.com>
@bjoern-m
Copy link
Contributor

Should we export the ThirdPartyError via the index.ts file of the frontend SDK?

@lfleischmann
Copy link
Member Author

Should we export the ThirdPartyError via the index.ts file of the frontend SDK?

Yes, I think we should.

@lfleischmann
Copy link
Member Author

Should we export the ThirdPartyError via the index.ts file of the frontend SDK?

37d6bd1

@lfleischmann
Copy link
Member Author

Currently the new third party sign in buttons don't have a loading state. When I click one of them it takes a while on my end before I get redirected (~3 sec). Would suggest to add a loading state, because I think it would feel a bit more dynamic. Also the other input elements should be disabled.

28179f0

Copy link
Contributor

@bjoern-m bjoern-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done! Approved from my side.

@lfleischmann lfleischmann merged commit eec7a47 into main Feb 23, 2023
@lfleischmann lfleischmann deleted the feat-thirdparty branch February 23, 2023 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants