197 Commits

Author SHA1 Message Date
7fe0862369 PKCE OAuth flow (#2266)
* feat: add auth prompt config option

* feat: add pkce oauth flow

When the oauth flow is initialized with a `code_verifier` the state cookie is optional and on hanko_token exchange the client must also send the `code_verifier` in addition to the `hanko_token`.

* fix: fix runtime errors & tests
2025-10-13 14:28:42 +02:00
ade86cc318 feat: add auth prompt config option (#2260) 2025-10-13 14:22:22 +02:00
7a78b8e172 fix: change module name corresponding to version 2025-09-25 19:15:20 +02:00
8057174398 fix: add all user properties to session (#2222)
Use all user properties to create a session in the create session endpoint in the admin router.
2025-08-26 16:18:04 +02:00
41e4155743 fix user deletion when using mysql as DBMS (#2202)
* fix: fix user deletion on mysql

* fix: use transaction for db query

* build: fix build
2025-08-26 16:16:00 +02:00
f231ae7e4a fix: oauth third party authentication with case insensitive email (#2196)
* feat: replace std slices

* feat: go mod tidy

* fix #2193: lowercase email

---------

Co-authored-by: franklin <kevin@franklinkim.de>
2025-07-24 14:08:40 +02:00
458c1d7438 fix: return correct user info in REST endpoint (#2163)
Return the correct user information structure in the REST endpoint, that the frontend-sdk expects.
2025-05-20 14:48:32 +02:00
b9bcf5e69b feat: user metadata 2025-05-16 13:47:10 +02:00
efeca4a76f feat: custom jwt claims 2025-04-16 15:17:48 +02:00
bc9eece531 feat: allow uuids of any version as user ids 2025-04-16 15:01:43 +02:00
fc86a5f594 chore: update go version to 1.24 2025-03-13 13:32:56 +01:00
63da219380 feat: introduce html mails (#2045) 2025-02-19 12:58:44 +01:00
c4f4249d68 Parse email_verified claim correctly from Apple ID token (#2054)
* fix: parse email_verified claim correctly

The email_verified claim in the apple identity token can either be a string or a bool. Before it was assumed that it is always a string, but when the claim is of type bool an error is returned. Now the claim type is checked and parsed accordingly. Also when the type check or parsing fails it is assumed that the email is not verified.

* test: add test for boolean claim

* chore: only log warning when error is not nil
2025-02-19 09:00:25 +01:00
c9684d1fe9 fix: create session in DB for old endpoints (#2052)
* fix: create session in DB for old endpoints

The old endpoints do not store the session in the DB, this leads to an unauthorized error in old hanko elements versions prior 1.0.0 when any endpoint is called that requires a session because they check if the session is stored in the DB.

* test: fix test
2025-02-14 21:00:38 +01:00
983000d94e feat(ee): saml idp initiated sso 2025-02-13 12:44:36 +01:00
e93788d774 feat: use exact template names for email.send webhook types 2025-02-11 19:07:46 +01:00
062aee4d45 fix: SAML issues (#2041)
Rename identities table columns for more clarity. Rename parameters,
arguments etc. to accommodate these changes.
    
Change that the SAML provider domain is persisted in the identities
table as the provider ID. Use the SAML Entity ID/Issuer ID of the
IdP instead.
    
Introduce saml identity entity (including migrations and a persister)
as a specialization of an identity to allow for determining the
correct provider name to return to the client/frontend and for assisting
in determining whether an identity is a SAML identity (i.e. SAML
identities should have a corresponding SAML Identity instance while
OAuth/OIDC entities do not).
2025-01-31 14:17:52 +01:00
b8c4771b57 feat: enhance session response (#2003)
* feat: enhance session response
* chore: respond with 'bad request' when token claims are invalid
2025-01-16 21:03:46 +01:00
d66b267646 feat: add facebook provider (#2007)
* add sign in with facebook

* feat: add facebook provider to factory function

* feat: add facebook config defaults

* feat: use newest facebook api version

* feat: make facebook provider consistent with other providers

* feat: add check for email

We cannot assume a user always has a valid email.
Even though it is not the used "me" endpoint, see:

https://developers.facebook.com/docs/graph-api/reference/user/

* docs: elaborate comment

* fix: fix third party tests

* feat: add facebook icon

* feat: add appsecret_proof to requests w. access token

* refactor: build userinfo url programmatically

* feat: map all available name claims

---------

Co-authored-by: Prathamesh <psvagare@gmail.com>
2025-01-15 21:28:23 +01:00
5023a53980 feat: email i18n 2025-01-13 12:58:43 +01:00
fc80743a93 fix: use lowered id to get third party provider (#2017)
* fix: use lowered id to get third party provider

* test: fix test

* test: increase db max lifetime
2025-01-06 16:39:06 +01:00
c40897ac09 feat: always persist sessions server-side, config adjustments (#1997)
* feat: always persist sessions server-side, config adjustments
2024-12-20 09:52:52 +01:00
21fd1d460f Feat custom user handle (#1978)
Add a custom user handle to a webauthn credential

---------

Co-authored-by: bjoern-m <56024829+bjoern-m@users.noreply.github.com>
2024-12-05 15:26:22 +01:00
e172e051fc fixes teamhanko/hanko#1624 (#1625)
uses configured cookie name in passcode handler

Co-authored-by: Wlad Meixner <hi@iamwlad.com>
2024-12-05 15:23:10 +01:00
d510fa5116 fix: check server side session for REST API endpoints (#1988)
Check server side sessions in session middleware for REST API endpoints.
Without it a server side session could be deleted, but can still be used at the REST API endpoints.
2024-12-05 10:08:45 +01:00
455e8e3677 feat: third party custom providers
* feat: third party custom providers

- New configuration option `third_party.custom_providers`. `custom_providers`
  is a map of arbitrarily chosen keys to a `CustomThirdPartyProvider` - this is
  implemented as a new type differing from the existing configuration type
  `ThirdPartyProvider` used for built-in providers because they have different
  configuration requirements.

- Both `ThirdPartyProvider` and `CustomThirdPartyProvider` types get a non-
  configurable, automatically populated `Name` (during the config's `PostProcess`)
  that sort of serves as an identifier/slug for the provider in order to
  distinguish provider types at runtime.
    - A `CustomThirdPartyProvider`s `Name` is automatically prefixed during
      `PostProcess` with a "custom_" prefix to ensure that providers can be
      distinguished at runtime.
    - A (built-in) `ThirdPartyProvider`s `Name` is "hard-coded" through the
      `DefaultConfig`.

- Built-in OAuth/OIDC provider implementations are currently instantiated
  on-demand instead of once at appliation startup (i.e. unlike SAML
  providers) - i.e. when a user requests auth/authz with a third party
  provider, only then a provider is instantiated and created via factory
  function (`thirdparty.GetProvider`).  Custom providers follow this
  pattern, hence the factory function had to be adjusted to take into account
  providers with the aforementioned "custom_" prefix (i.e.: if it is a
  "custom_" provider, instantiate a `customProvider` implementation).

- The `customProvider` implementation uses the `go-oidc` library. Instances
  of providers of the type this library offers can be instantiated by passing
  in an `issuer` URL. Such an instantiation automatically attempts to retrieve
  an OIDC discovery document from a `.well-known` endpoint. This also performs
  an issuer validation. Providers configured to not use OIDC discovery (i.e.
  `use_discovery` in the `CustomThirdPartyProvider` is `false` or omitted) do
  not do this issuer check.

- The `customProvider` implementation is further based on the assumption that
  provider user data is only extracted from a userinfo endpoint response, i.e.
  in case of an OIDC provider, the implementation does not make use of the ID
  token - no validation is performed on the ID token.

- The `customProvider` implementation requires configuring a list of `scopes`:
  because the custom providers allow configuring both OAuth as well as OIDC
  providers, we cannot simply set a default set of scopes, e.g. `openid`, which
  is a required claim for OIDC - some providers return errors on unknown claims
  so setting this would make the third party auth process prone to errors.

- The `customProvider` implementation allows for a simple mapping of claims
  contained in the userinfo response from the provider to "known" standard OIDC
  conformant claims at the Hanko backend (defined in the `thirdparty.Claims`
  struct) through an `attribute_mapping` configuration option. The mapping is a
  simple one-to-one mapping, i.e. no complex mapping instructions are possible,
  e.g. mapping concatenations of multiple claims in the provider data source or
  similar. Any other non-standard claims returned by the provider are placed in
  a `custom_claims` attribute. Except for the user ID (`sub`), `email` and
  `email_verified` claims the third party functionality currently does not allow
  accessing this user data but there's a good chance this will change in the future,
  so I tried to make sure that any info retrieved from the provider is somehow
  preserved (it is persisted in the `data` column for an `identity` btw. and updated
  on every login with the provider).
    - I also noticed that the `thirdparty.Claims` were missing the `address` claim,
      so I added that for completeness' sake.

- The changes also fix a "bug" in the account `linking` logic whereby third party
  connections were established by simply assuming that the email retrieved from the
  provider was verified. So, even if the email address at the provider was not
  verified (or the provider simply did/does not provide info about the verification
  status) an account was created and/or linked and the flow API capabilities of
  automatically triggering a passcode if the backend was configured to require email
  verification would not take effect. This was a wrong assumption and the verification
  status is now based on the actual value retrieved from the provider.
- In case of a triggered passcode, the changes also modify the token exchange
   action to prevent showing a `back` button/link, since it does not make sense to
   go `back` to anything right after the token exchange - there is nothing to go
   "back" to.
2024-12-04 13:40:08 +01:00
c264108f87 Admin api changes (#1974)
* feat: return mfa only flag

* feat: add webauthn admin handler

* feat: add webauthn credential handler to router

* feat: add password mgmt admin endpoints

* feat: add sessions admin handler

* feat: add otp admin handler

* feat: add otp to admin user dto

* test: add admin password handler test

* test: add admin webauthn handler test

* test: add admin session handler test

* test: add admin otp handler test

* chore: merge both loadDto functions

* tests: fix test name typos
2024-12-03 11:22:52 +01:00
f32f48e85b feat: trusted devices and 'remember me' (#1982) 2024-11-29 11:06:47 +01:00
b643256e1c feat: add session creation endpoint (#1969) 2024-11-12 14:33:34 +01:00
bc04b729dd feat: introduce mfa (#1645)
* feat: create otp_secrets table

* feat: create otp secret model

* feat: add mfa_only column to webauthn_credentials table

* feat: add mfa only field to webauthn credential model

* feat: add mfa config (#1607)

* feat: add otp secret persister (#1613)

* feat: MFA usage sub flow (#1614)

* feat: add mfa-usage sub-flow

---------

Co-authored-by: Lennart Fleischmann <67686424+lfleischmann@users.noreply.github.com>

* feat: include platform authenticator availybility in the preflight flow (#1615)

* feat: add mfa creation subflow

* feat: adjust registration flow

* feat: integrate mfa usage sub-flow

* feat: add pages for mfa (#1622)

* feat: profile flow adjustments for mfa support

* fix: suspension logic for mfa deletion actions

* feat: use dedicated action for security key creation options

* fix: mfa method stash entry can be stale on profile flow

The mfa_creation subflow sets an mfa_method stash value so that
when creating and persisting the credential the mfa_only flag can
be set correctly in the hook responsible for that. But the profile flow
never "ends" and and returns to the initial state so I can also
register a passkey afterwards. The mfa_method stash key remains on the
stash but is used in the hook nonetheless, so the passkey is incorrectly
recognized as a security key.

The mfa_method key is now deleted after successfully persisting the
credential/security_key. This should not have an effect on the login
flow because the mfa_creation subflow is the last subflow to be
executed. It also should not affect the registration flow, because the
hook is not applied in the registration flow (persistence of data is
all handled in the create_user hook).

* feat: add new icons and english translations (#1626)

* fix: credential id encoding corrected (#1628)

* feat: add audit logs for mfa creation

* feat: add a skip link to the mfa method chooser (#1630)

* feat: save the security key during login (#1629)

* feat: show security keys in profile

* feat: add authenticator app management to profile (#1633)

* feat: add authenticator app management to profile
* feat: passkey counts as second factor

* feat: prohibit security key first factor usage

* feat: add all WA creds to exclude list on registration

* refactor: mfa stash entries and webauthn credential persistence

Renames MFA stash entry for indicating usage (login) method to make its
meaning more explicit. Also removes code persisting a webauthn credential
from the attestation verification action in the onboarding flow because
this is already done by a shared hook.

* refactor: simplify WA creation call

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

* chore: adjust mfa flow

* fix: mfa onboarding always shown during login

* fix: mfa onboarding not shown after password or email creation during login

* fix: mfa onboarding not shown without user detail onboarding

* fix: correct skip/back behaviour

* feat: reuse generated otp secret when the code is invalid

* chore: skip mfa prompt if the user only has a passkey

* chore: adjust login flow 

* chore: skip mfa prompt if the user only has a passkey

* chore: refactor and improve mfa onboarding

* fix: no mfa onboarding when passwords and passkeys are disabled

* fix: only show mfa onbooarding once

* feat: add a function to the flowpilot to check whether a state has been visited

* chore: adjust recovery flow (#1655)

* feat: disable password, passcode endpoints when mfa enabled

* Feat: remember last used login method (#1674)

* chore: remove omitempty from boolean (#1676)

* chore: improved error handling (#1679)

* chore: improved error handling

* feat: add missing translations (#1681)

* feat: update aaguid list (#1678)

* fix: do not suspend webauthn action for MFA (#1778)

Do not suspend the `webauthn_verify_attestation_response` action when passkeys are disabled, but security keys and MFA are enabled.

* fix: change texts (#1785)

Change texts regarding security creation to be more consistent across the flows and to be more precise.

* Fix: UI issues (#1846)

* fix: loading spinner alignment corrected

* fix: auth app deletion link is shown while deletion is not allowed

* Chore: remove test persister (#1876)

* chore: remove deprecated test persister

* chore: replace test persister calls

* chore: add saml state fixtures

* Update backend/flow_api/services/webauthn.go

Co-authored-by: Frederic Jahn <frederic.jahn@hanko.io>

* Update backend/dto/profile.go

Co-authored-by: Frederic Jahn <frederic.jahn@hanko.io>

* fix: otp validation uses the rate limiter key for passwords

* chore: add otp-limits to the default config

* chore: add explanation for 'UserVerification' setting on security keys

---------

Co-authored-by: Lennart Fleischmann <lennart.fleischmann@hanko.io>
Co-authored-by: Lennart Fleischmann <67686424+lfleischmann@users.noreply.github.com>
Co-authored-by: Frederic Jahn <frederic.jahn@hanko.io>
2024-11-01 19:38:30 +01:00
9dbc62524a feat: Server side sessions (#1673)
* feat: add server side sessions

* feat: add lastUsed & admin endpoint

* feat: add session list to elements

* fix: fix public session endpoint

* chore: only store session info when enabled

* build: update go mod

* feat: add translations

* test: fix tests

* feat: change path

* feat: return userID on session validation endpoint

* feat: move all session endpoints to public router

* fix: add missing translation

* fix: add missing structs

* chore: align session persister with other persisters

* fix: use correct translation label

* chore: add db validator to session model

* feat: create server side session from cmd

* fix: fix review findings
2024-10-15 11:36:32 +02:00
5ddbdf9a64 chore(webhooks): update webhook.go (#1666)
udpate -> update
2024-10-05 00:13:27 +02:00
a7e4c67353 feat(admin-api): get users by multiple ids 2024-10-01 12:02:44 +02:00
38a11deffa fix: only use transaction connection in a transaction (#1598)
* fix: only use transaction connection in a transaction

* test: fix webhook tests
2024-08-28 11:56:09 +02:00
3471da6a65 fix: check for one primary email
only create a user through the admin API when emails are set and one of them is marked as primary
2024-08-26 15:24:41 +02:00
af5b37bb15 test: fix test 2024-08-26 15:24:41 +02:00
402e8ace72 test: fix tests 2024-08-26 15:24:41 +02:00
117f6f4a49 feat: return complete user in admin API
add username, identities and password credential to the return object when calling /users/{user_id} from the admin API
2024-08-26 15:24:41 +02:00
92a8743c14 feat: update DTO with username field (#1583) 2024-08-23 11:12:46 +02:00
0835215654 chore: add webhooks to flow-api (#1574) 2024-08-13 16:00:52 +02:00
601ffaae92 Introduce Flowpilot - integration (#1532)
This pull request introduces the new Flowpilot system along with several new features and various improvements. The key enhancements include configurable authorization, registration, and profile flows, as well as the ability to enable and disable user identifiers (e.g., email addresses and usernames) and login methods.

---------

Co-authored-by: Frederic Jahn <frederic.jahn@hanko.io>
Co-authored-by: Lennart Fleischmann <lennart.fleischmann@hanko.io>
Co-authored-by: lfleischmann <67686424+lfleischmann@users.noreply.github.com>
Co-authored-by: merlindru <hello@merlindru.com>
2024-08-06 16:07:29 +02:00
4bea1e3361 fix: don't override error before return (#1447) 2024-04-29 11:44:46 +02:00
def7ad37a0 [FEAT] disable email delivery (#1419)
* feat: add config to disable email delivery

* chore: update config schema

* docs: add new config parameter

* test: fix test

* fix: rename email webhook event

* docs: Update backend/docs/Config.md

Co-authored-by: Lennart Fleischmann <67686424+lfleischmann@users.noreply.github.com>

---------

Co-authored-by: Lennart Fleischmann <67686424+lfleischmann@users.noreply.github.com>
2024-04-18 15:15:02 +02:00
7276db13bb fix: fix saml login for existing users (#1434) 2024-04-17 13:55:18 +02:00
92c5d21e21 feat(thirdparty): add microsoft provider 2024-04-17 11:12:13 +02:00
01fa397672 feat(webauthn): change default attestation mode
Changes the default attestation conveyance preference from 'none' to 'direct' for better AAGUID handling on Windows.

Co-authored-by: Stefan Jacobi <stefan.jacobi@adesso.de>
2024-04-10 15:31:11 +02:00
5ceb6bb030 fix(jwt): add updated email on user create (#1416)
* add check of email object is nil to DTO transformation - prevents runtime nil exception

* fetch updated emails for user before creating session token

Co-authored-by: Stefan Jacobi <stefan.jacobi@adesso.de>
2024-04-03 16:15:25 +02:00
8ab246dc12 feat(jwt): add email claim to session JWT (#1404)
* add email claim which contains email address, is_verified and is_primary values
* cleanup some unused stuff

Closes: #1388

Co-authored-by: Stefan Jacobi <stefan.jacobi@adesso.de>
2024-03-25 15:25:02 +01:00
8d745cc742 feat(webhooks): add webhooks trigger to thirdparty auth
* add user.create event trigger to thirdparty signup
* add user.update when an email is added to an identity
* add email.create when email is created

Closes: #1361
2024-02-27 11:17:32 +01:00
7d57bf6231 feat(thirdparty): add discord provider
Co-authored-by: Scott Plunkett <scott@scottplunkett.com>
2024-02-19 17:59:14 +01:00