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

Introduce Flowpilot - integration #1532

Merged
merged 281 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
281 commits
Select commit Hold shift + click to select a range
19a0443
refactor flow api actions
bjoern-m Nov 20, 2023
76fc4b1
refactor: move action name constants into the related packages
bjoern-m Nov 20, 2023
36e8db1
fix action struct name
bjoern-m Nov 20, 2023
57cf495
refactor: rename actions, hooks, structs and files
bjoern-m Nov 20, 2023
b3ca375
post-process webauthn config
bjoern-m Nov 20, 2023
f46f76c
refactor: rename a go file that belongs to the login flow
bjoern-m Nov 21, 2023
a6e1530
refactor: adds a webauthn service
bjoern-m Nov 22, 2023
81118ab
Update backend/flow_api/shared/services/webauthn.go
bjoern-m Nov 23, 2023
c9b6cb8
refactor: pull passcode verification from action into service
lfleischmann Nov 24, 2023
bb3697b
refactor: change package structure
lfleischmann Nov 24, 2023
df9363d
chore: remove commented code
lfleischmann Nov 24, 2023
96dc853
refactor: rename service receivers
lfleischmann Nov 24, 2023
6b8d5ce
refactor: extract password logic into password service
lfleischmann Nov 29, 2023
69b9b85
feat: add hook for issuing session/cookie/jwt
lfleischmann Nov 29, 2023
1ca6f6f
chore: passcode functionality improved
bjoern-m Nov 30, 2023
147ec48
chore: small fixes
bjoern-m Dec 1, 2023
61aa537
feat: parent flow can add hooks for subflow states
bjoern-m Dec 4, 2023
c82db5c
fix: hook execution corrected
bjoern-m Dec 4, 2023
32fac03
fix: skip on passkey onboarding in registration flow
lfleischmann Dec 14, 2023
930bfcd
fix(flowpilot): email regex match on empty or nil input value
lfleischmann Dec 14, 2023
c0ca487
fix: suspend password login actions when passwords are disabled
lfleischmann Dec 15, 2023
61332ae
feat: add links to a flow
FreddyDevelop Dec 19, 2023
01913e2
feat: generate OAuth links when provider enabled
FreddyDevelop Dec 20, 2023
e01ef12
fix: fix review findings
FreddyDevelop Dec 20, 2023
5b6738e
chore: typos & renaming
FreddyDevelop Dec 20, 2023
34cb966
chore: typo
FreddyDevelop Dec 20, 2023
8b327d8
chore: make comment more clear
FreddyDevelop Dec 21, 2023
59ebaab
fix: add missing passkey onboarding on login
lfleischmann Dec 21, 2023
e47a900
fix(flow-api): register login identifier logic
lfleischmann Dec 22, 2023
83b8938
feat: add profile flow base
lfleischmann Dec 6, 2023
edfb078
fix: passkey onboarding skip action
lfleischmann Jan 15, 2024
6b3d9a1
feat: contextualize entire user model in profile flow
lfleischmann Jan 16, 2024
be0b3b3
fix: check for allowed characters in username set action
lfleischmann Jan 17, 2024
bc8728f
feat: add profile data dto for flow api
lfleischmann Jan 18, 2024
377d190
feat: extend user persister get method
lfleischmann Jan 18, 2024
575cab3
feat: rework flow api profile action initializations
lfleischmann Jan 18, 2024
7b7d870
fix: json ignore emails field in user model again
lfleischmann Jan 19, 2024
a847e0c
feat: share email verification hook
lfleischmann Feb 7, 2024
e58cecf
fix: fix concurrency issue (#1336)
FreddyDevelop Feb 14, 2024
e4fb3fb
fix: restore restore schema generation logic
lfleischmann Feb 15, 2024
209122c
fix(flow-api): issue session hook includes x-domain scenario
lfleischmann Feb 16, 2024
e9f078f
fix: flow api profile after concurrency fix
lfleischmann Feb 22, 2024
f64464e
fix: nil pointer exception when accessing the flow error (#1345)
bjoern-m Feb 22, 2024
015e56b
Flow api improve handling when email is unknown (#1240)
bjoern-m Feb 22, 2024
f0e9d73
fix: correct main merge errors
lfleischmann Feb 22, 2024
ed3c284
fix: add missing test persister implementation
lfleischmann Feb 22, 2024
7e287f3
feat(flow-api): improve thirdparty integration
lfleischmann Mar 7, 2024
a631fa3
feat(flow-api): add audit logs
lfleischmann Mar 11, 2024
4d763b9
feat(flow-api): suspend oauth action when no provider enabled
lfleischmann Mar 11, 2024
c90ff63
feat(flow-api): enable webauthn login with conditional mediation
lfleischmann Mar 12, 2024
7a14bd7
fix(flow-api): misc issues
lfleischmann Apr 17, 2024
bfd2d62
feat: introduce flow-api sdk and adjust the api response (#1299)
bjoern-m Apr 17, 2024
b32aff4
chore: individual input fields for 'identifier', 'email' and 'usernam…
bjoern-m Apr 19, 2024
a2a20e5
Flow api adjustments (#1438)
bjoern-m Apr 19, 2024
399d1d5
fix: test client
lfleischmann Apr 19, 2024
b6b0a08
Flow api adjustments (#1442)
bjoern-m Apr 22, 2024
cc25c1f
feat: add user data to payload on success (#1444)
bjoern-m Apr 24, 2024
976b122
feat: Hanko elements with flow api (#1443)
bjoern-m May 22, 2024
428e648
Feat add conditional UI (#1472)
FreddyDevelop Jun 3, 2024
254f4d2
wip
lfleischmann Apr 19, 2024
ce91ea3
wip2
lfleischmann Apr 22, 2024
bf0dc06
wip2
lfleischmann Apr 29, 2024
905a568
wip4: registration subflows
lfleischmann Apr 29, 2024
98146aa
wip5
lfleischmann May 3, 2024
aa58cee
feat: keep track of (sub-)flow call hierarchy
lfleischmann May 7, 2024
25f1bc6
feat: simplify register login identifier action
lfleischmann May 7, 2024
90c9cda
chore: adjust registration flow actions
bjoern-m May 8, 2024
5060a49
chore: adjust login flow and remove unused files
bjoern-m May 8, 2024
368d79c
chore: change hook execution order
bjoern-m May 8, 2024
5698e52
wip: flow continuation after login
bjoern-m May 13, 2024
e7fe720
chore: restructure login flow
bjoern-m May 13, 2024
27f145a
chore: improve function to generate login states
bjoern-m May 14, 2024
c1d3efe
chore: remove unused function
bjoern-m May 14, 2024
5106538
chore: adjust context interfaces, flow names can be obtained
bjoern-m May 14, 2024
b477a37
wip: ajdust the login flow
bjoern-m May 14, 2024
f3e306a
fix: action initialization, when action names are reused
bjoern-m May 15, 2024
3eb627f
chore: change flow package structure to prevent import or initializat…
bjoern-m May 15, 2024
df5e598
chore: refactoring, flow path generation improved
bjoern-m May 16, 2024
04e42d3
chore: add flow path on debug, fix flow path updates on back actions
lfleischmann May 17, 2024
09c7e42
fix: skip actions of the credential onboarding flow
bjoern-m May 17, 2024
46cfedd
chore: enhance path util
bjoern-m May 17, 2024
f25d78a
chore: fix credential onboarding skip actions and add chooser
lfleischmann May 21, 2024
62cf1a4
chore: move registration method chooser to credential onboarding
lfleischmann May 21, 2024
19a43e0
chore: combine login subflows
lfleischmann May 21, 2024
d5d795d
fix skip actions
bjoern-m May 22, 2024
71ed347
adjust skip actions once again, adjust registration flow
bjoern-m May 22, 2024
13cf3a4
add user details subflow, fix various issues
bjoern-m May 23, 2024
c76c83c
adjust config to accept the new acquire on login options
bjoern-m May 23, 2024
fa21a66
chore: make profile work with new config
lfleischmann May 24, 2024
ddd90de
adjust back actions
bjoern-m May 27, 2024
c397eea
use new config parameter to enable password recovery
bjoern-m May 27, 2024
6c11d49
call hook to refresh the user data only once per request
bjoern-m May 27, 2024
29cdbae
make all code use new config options
lfleischmann May 28, 2024
15f7eb8
add parameter to convert the legacy config
bjoern-m May 29, 2024
7e3ede7
enable email verification and username onboarding after third party auth
lfleischmann May 30, 2024
d23bf6f
ensure unique usernames
lfleischmann May 30, 2024
f85bf99
fix: user model usernames null handling
lfleischmann Jun 4, 2024
b3f377f
fix: login credential onboarding logic
lfleischmann Jun 4, 2024
22f56d2
improve flow path feature
bjoern-m May 31, 2024
4d54ced
fix response schema generation
bjoern-m Jun 4, 2024
9f8d5c8
fix: remove third party configs
lfleischmann Jun 4, 2024
365190c
fix: remove notes file
lfleischmann Jun 4, 2024
6c7476a
fix nil pointer exception while writing the audit log
bjoern-m Jun 5, 2024
dc729f6
add create email page
bjoern-m Jun 5, 2024
736428e
fix email verification after user detail onboarding
bjoern-m Jun 5, 2024
5b282b3
add create username page
bjoern-m Jun 5, 2024
e1c6b97
fix copy to stash function
bjoern-m Jun 5, 2024
7c52cf6
add credential method chooser
bjoern-m Jun 5, 2024
5982cf3
adjust back-actions
bjoern-m Jun 6, 2024
d63ab76
removed finalization from action interface
bjoern-m Jun 7, 2024
e4bd711
adjust back actions
bjoern-m Jun 11, 2024
b000088
dissovle utils package
bjoern-m Jun 12, 2024
4637690
added csrf tokens + refactoring
bjoern-m Jun 12, 2024
8d5ed98
fix csrf tokens not updating
bjoern-m Jun 12, 2024
605ed05
feat: make saml flow api ready
lfleischmann Jun 13, 2024
4abf88b
fix ui states for username and email
bjoern-m Jun 18, 2024
8268027
fix issues with password recovery
bjoern-m Jun 18, 2024
00a8d84
adjust profile, translations and fix an issue where webauthn is not w…
bjoern-m Jun 18, 2024
ae9aff0
feat: add thirdparty login to elements (#1468)
FreddyDevelop Jun 6, 2024
2a68c27
feat: third party only flow(s)
lfleischmann Jun 19, 2024
441dcb5
fix: do not panic in saml service constructor
lfleischmann Jun 20, 2024
239d948
fix: email deletion
lfleischmann Jun 20, 2024
0434a34
chore: remove unnecessary error handling in capabalitites action
lfleischmann Jun 20, 2024
f7ab674
fix: legacy-flow api compatibility issues
lfleischmann Jun 20, 2024
6086ca0
refactor: restructure code that relates to the 'stash' functionality
bjoern-m Jun 21, 2024
019ff31
refactor: flowpilot interfaces
bjoern-m Jun 21, 2024
cf8ee74
chore: rework back and skip actions
bjoern-m Jun 24, 2024
90dc589
refactor flowpilot interfaces
bjoern-m Jun 24, 2024
585438b
refactor: prefix response structs with 'Response...' instead of 'Publ…
bjoern-m Jun 24, 2024
9c6907c
refactor allowed values for flow action inputs
bjoern-m Jun 24, 2024
4ce58cb
refactor response generation
bjoern-m Jun 24, 2024
213ba1c
small flowpilot refactoring
bjoern-m Jun 24, 2024
bf59d0c
introduce flow name constants
bjoern-m Jun 24, 2024
c9ce355
fix a validation bug
bjoern-m Jun 25, 2024
c182f5e
introduce constants for json manager paths
bjoern-m Jun 25, 2024
05fd5ab
refactor: remove json path type again
bjoern-m Jun 25, 2024
2188eb6
fix: passkey limit json tag
lfleischmann Jun 26, 2024
b48a868
refactor: rename 'toPublic...' methods to 'toResponse...'
lfleischmann Jun 26, 2024
c4a60b9
fix: elements username and password i18n label typos
lfleischmann Jun 26, 2024
34eb35d
fix: username set action incorrectly updates username
lfleischmann Jun 26, 2024
158b95d
Flow api config new and flowpilot updates (#1507)
bjoern-m Jun 28, 2024
8573eac
fix: passcode template not stashed when logging in with username
bjoern-m Jul 1, 2024
e00db01
fix: passcode template not stashed on registration with username
bjoern-m Jul 1, 2024
c64f636
fix: can register without email and username
bjoern-m Jul 1, 2024
11e704f
fix: primary email can't be deleted
bjoern-m Jul 1, 2024
9d9c8ee
fix: skip actions adjusted in case email verification is turned off
bjoern-m Jul 1, 2024
9dc7ae7
refactor: remove unused code from flowpilot
bjoern-m Jul 1, 2024
11cc4f3
fix: error message not shown or traslation missing
bjoern-m Jul 1, 2024
9a8cce5
chore: split password_set action into password_create and password_up…
bjoern-m Jul 1, 2024
04f93c4
fix: passcode template not selected, adjust skip actions
bjoern-m Jul 2, 2024
b48efaa
chore: revert Set() function moved to another flowpilot interface
bjoern-m Jul 2, 2024
4a5df94
fix: solved issue when deleting a webauthn credential
bjoern-m Jul 2, 2024
abf7155
fix: profile email deletion
bjoern-m Jul 3, 2024
5df80f2
fix: flowpilot inputs not updated
bjoern-m Jul 3, 2024
f050209
fix: profile credential deletion logic
bjoern-m Jul 3, 2024
f0e847d
fix: input errors not shown
bjoern-m Jul 3, 2024
6c5a236
chore: flowpilot fixes, updates and refactoring
bjoern-m Jul 4, 2024
7aea3de
chore: adjust generic client
bjoern-m Jul 4, 2024
3c18bc9
chore: flow-api refactoring, bug fixes and the ability to specify the…
bjoern-m Jul 4, 2024
29c2c19
chore: adjust errors returned by the flow-api
bjoern-m Jul 4, 2024
d2f78e9
chore: add error missing message translations
bjoern-m Jul 4, 2024
06716e9
feat: input values can be trimmed and converted to lower case
bjoern-m Jul 4, 2024
f06b639
fix: wrong translation key when email already exists
bjoern-m Jul 5, 2024
eee201a
chore: revert change in action context
bjoern-m Jul 5, 2024
1b603af
fix: quick fix for cleaning up stash data
bjoern-m Jul 5, 2024
6dadc37
refactor: rename response attributes, add json omitempty tags
lfleischmann Jul 9, 2024
ac37cff
fix: use snake case for state serialisation to json
FreddyDevelop Jul 9, 2024
f041f31
Revert "refactor: rename response attributes, add json omitempty tags"
lfleischmann Jul 9, 2024
6915579
chore: add translations and icons for method chooser pages
bjoern-m Jul 10, 2024
e933d0e
chore: adjust profile translations and remove delete email section if…
bjoern-m Jul 10, 2024
d59bf28
feat: username deletion via profile
bjoern-m Jul 12, 2024
5522847
fix: missing variable added, suspension logic updated
bjoern-m Jul 15, 2024
99482d7
fix: skip password action
bjoern-m Jul 15, 2024
404512b
fix: prevent copying empty values to the stash
bjoern-m Jul 15, 2024
d69275f
chore: css adjustments
bjoern-m Jul 15, 2024
178d33b
add flow api logging (#1519)
FreddyDevelop Jul 18, 2024
1c71e24
Flow api fix config usage (#1518)
FreddyDevelop Jul 18, 2024
d1b4642
fix: login with username, without having an email address, while pass…
bjoern-m Jul 15, 2024
ef71faf
fix: generate onboarding steps after passkey login
bjoern-m Jul 16, 2024
f4db04d
chore: reimplement the stash
bjoern-m Jul 17, 2024
8d16774
fix: hook execution on error corrected
bjoern-m Jul 17, 2024
de022ab
fix: acion input issues resolved
bjoern-m Jul 17, 2024
1be18c4
refactor: rename csrf token key in input data
lfleischmann Jul 19, 2024
f184670
refactor: unmarshal input_data into map instead of string
lfleischmann Jul 19, 2024
c35ff40
fix: correct email onboarding after login
bjoern-m Jul 18, 2024
c06fa7a
refactor: profile endpoint session validation
lfleischmann Jul 22, 2024
5e985a8
fix: add tags to all config parameters (#1525)
FreddyDevelop Jul 22, 2024
a86d3bb
chore: addjust error handling
bjoern-m Jul 22, 2024
249839b
refactor: move csrf_token property in request bodies
lfleischmann Jul 22, 2024
562ee53
chore: remmove outdated test files
bjoern-m Jul 22, 2024
28da735
chore: integrate flow-api
bjoern-m Jul 23, 2024
e0e4cf4
chore: add missing state names and remove outdated ones
bjoern-m Jul 23, 2024
14a5160
refactor: improve hook execution error messages
bjoern-m Jul 23, 2024
49dab48
fix: error after user account has been deleted
bjoern-m Jul 23, 2024
e1961b4
chore: example.html imports hanko-elements from the CDN
bjoern-m Jul 23, 2024
f708d25
refactor: remove console.log calls
bjoern-m Jul 23, 2024
7e0055a
fix: correct third party state name
bjoern-m Jul 23, 2024
6f22e84
refactor: fix es-lint errors
bjoern-m Jul 23, 2024
80a8356
chore: username validation adjusted
bjoern-m Jul 23, 2024
782b9cf
chore: remove unused passcode.FlowID field
bjoern-m Jul 23, 2024
4bc7990
chore: create a username table
bjoern-m Jul 23, 2024
88e4bf7
chore: improve error message styles
bjoern-m Jul 24, 2024
e6e2c25
feat: stash data can be compressed
bjoern-m Jul 25, 2024
24f5e51
chore: add username persister test implementation
bjoern-m Jul 26, 2024
4ecec0e
chore: remove unused method from the username persistence interface
bjoern-m Jul 26, 2024
254ba8c
fix: test files corrected
bjoern-m Jul 26, 2024
468744f
fix: template render test
bjoern-m Jul 26, 2024
6a607ab
fix: compile error nextjs example
bjoern-m Jul 26, 2024
619ebca
fix: test config for EmailDelivery adjusted
bjoern-m Jul 26, 2024
c09f6f6
fix: passcode tests
bjoern-m Jul 26, 2024
a6fe3d5
fix: user payload missing after login
bjoern-m Jul 29, 2024
40fca2c
chore: remove redundant user_id from payload
bjoern-m Jul 29, 2024
2b45873
chore: add user_id to success event
bjoern-m Jul 29, 2024
609346c
fix: password.optional and passkey.optional has no effect within the …
bjoern-m Jul 29, 2024
c117bbf
Merge pull request #1533 from teamhanko/introduce_flowpilot_compress-…
bjoern-m Jul 30, 2024
1d004e3
fix: nil pointer after registration
bjoern-m Jul 30, 2024
c86aaa9
fix: onboarding states generation
lfleischmann Aug 1, 2024
26a3d48
test: fix passcode handler test using new config options
lfleischmann Aug 1, 2024
da701db
fix: wrong acquire_on option checked
lfleischmann Aug 1, 2024
acf8350
fix: skip onboarding chooser when passkeys and passwords are required
lfleischmann Aug 1, 2024
b0fb3e1
fix: suspension logic in skip_passkey and skip_password
lfleischmann Aug 1, 2024
fd93beb
chore: the hanko-elements can be used in nextjs without dynamic imports
bjoern-m Jul 29, 2024
cabff98
Merge branch 'main' into introduce_flowpilot_integration
lfleischmann Aug 2, 2024
d6ab5a5
refactor: sort main config struct
lfleischmann Jul 24, 2024
3d863b2
feat: config docs markdown generation
lfleischmann Jul 29, 2024
67fc062
ci: add workflow for generating and pushing config docs to wiki
lfleischmann Jul 30, 2024
19aa912
fix: readd old password config option, deprecate and convert properly
lfleischmann Jul 31, 2024
8994bd2
docs: change passkey.optional and password.optional config option des…
lfleischmann Aug 1, 2024
2ab71f5
fix: remove work in progress commands committed by mistake
lfleischmann Aug 1, 2024
dae8f0b
fix: apply suggestions from code review
lfleischmann Aug 1, 2024
7627aea
fix: explain that linking is based on email matching in allow_linking…
lfleischmann Aug 1, 2024
e1aff47
fix: make third party provider doc comments consistent
lfleischmann Aug 1, 2024
c7f3dc2
fix: rate limit doc comments
lfleischmann Aug 1, 2024
60f1f9c
fix: adjust optional property comment docs
lfleischmann Aug 1, 2024
f5ba1f9
chore: regenerate json schema
lfleischmann Aug 1, 2024
b32120b
fix: token tests
lfleischmann Aug 5, 2024
e93531f
fix: email admin tests
lfleischmann Aug 5, 2024
6239a0d
fix: email tests
lfleischmann Aug 5, 2024
bea0452
fix: thirdparty tests
lfleischmann Aug 5, 2024
a86479d
fix: webauthn tests
lfleischmann Aug 5, 2024
e21cb29
Change convert_legacy_config default value (#1552)
FreddyDevelop Aug 5, 2024
e929588
ci: update node verson in build frontend workflow
lfleischmann Aug 5, 2024
b3478a2
ci: use even newer node version in frontend build workflow
lfleischmann Aug 5, 2024
77d4fa6
Merge branch 'main' into introduce_flowpilot_integration
lfleischmann Aug 5, 2024
08544bc
docs: add safari cookie secure flag note
lfleischmann Aug 5, 2024
6bb9b1b
fix: legacy passkey and passcode handler respect new config
lfleischmann Aug 6, 2024
fbdfe4b
fix: passcode and webauthn handler tests
lfleischmann Aug 6, 2024
91a8560
chore: adjust events, update examples
bjoern-m Aug 5, 2024
8b14945
chore: remove unused files
bjoern-m Aug 6, 2024
795621f
chore: remove another dynamic import of hanko-elements
bjoern-m Aug 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/build-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: v18.14.2
node-version: v20.16.0

- name: Install dependencies
working-directory: ./frontend
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/generate-config-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Generate config reference markdown

on:
workflow_dispatch:

jobs:
config:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.20'

- uses: actions/setup-node@v4
with:
node-version: '20.16.0'
registry-url: https://registry.npmjs.org/

- name: Checkout backend
uses: actions/checkout@v4
with:
path: hanko

- name: Checkout backend wiki
uses: actions/checkout@v4
with:
repository: ${{github.repository}}.wiki
path: wiki

- name: Generate config docs
working-directory: ./hanko/backend
run: |
go generate ./...
go run main.go schema json2md

- name: Clean md file endings
working-directory: ./hanko/backend
run: |
find ./docs/.generated/config/md -type f -name "*.md" -exec sed -i "s/\.md//g" "{}" \;

- name: Copy generated files
working-directory: ./hanko/backend
run: |
mkdir -p $GITHUB_WORKSPACE/wiki/reference/config
rm $GITHUB_WORKSPACE/wiki/reference/config/*.md 2>/dev/null || true
cp ./docs/.generated/config/md/*.md $GITHUB_WORKSPACE/wiki/reference/config

- name: Commit and push to wiki
working-directory: ./wiki
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m "action: Autogenerate config reference docs"
git push origin HEAD
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Generated files
.generated

# MacOS
.DS_Store

Expand Down
2 changes: 2 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ COPY template template/
COPY utils utils/
COPY mapper mapper/
COPY webhooks webhooks/
COPY flow_api flow_api/
COPY flowpilot flowpilot/

# Build
RUN go generate ./...
Expand Down
2 changes: 2 additions & 0 deletions backend/Dockerfile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ COPY rate_limiter rate_limiter/
COPY thirdparty thirdparty/
COPY build_info build_info/
COPY middleware middleware/
COPY flow_api flow_api/
COPY flowpilot flowpilot/
COPY template template/
COPY utils utils/
COPY mapper mapper/
Expand Down
126 changes: 78 additions & 48 deletions backend/audit_log/logger.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package auditlog

import (
"fmt"
"github.com/gobuffalo/pop/v6"
"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"
zeroLog "github.com/rs/zerolog"
zeroLogger "github.com/rs/zerolog/log"
"github.com/teamhanko/hanko/backend/config"
"github.com/teamhanko/hanko/backend/persistence"
"github.com/teamhanko/hanko/backend/persistence/models"
"github.com/teamhanko/hanko/backend/utils"
"os"
"strconv"
"time"
)

type Logger interface {
Create(echo.Context, models.AuditLogType, *models.User, error) error
CreateWithConnection(*pop.Connection, echo.Context, models.AuditLogType, *models.User, error) error
Create(echo.Context, models.AuditLogType, *models.User, error, ...DetailOption) error
CreateWithConnection(*pop.Connection, echo.Context, models.AuditLogType, *models.User, error, ...DetailOption) error
}

type logger struct {
persister persistence.Persister
storageEnabled bool
logger zeroLog.Logger
consoleLoggingEnabled bool
mustMask bool
}

func NewLogger(persister persistence.Persister, cfg config.AuditLog) Logger {
Expand All @@ -43,78 +43,108 @@ func NewLogger(persister persistence.Persister, cfg config.AuditLog) Logger {
storageEnabled: cfg.Storage.Enabled,
logger: zeroLog.New(loggerOutput),
consoleLoggingEnabled: cfg.ConsoleOutput.Enabled,
mustMask: cfg.Mask,
}
}

func (l *logger) Create(context echo.Context, auditLogType models.AuditLogType, user *models.User, logError error) error {
return l.CreateWithConnection(l.persister.GetConnection(), context, auditLogType, user, logError)
}
type DetailOption func(map[string]interface{})

func (l *logger) CreateWithConnection(tx *pop.Connection, context echo.Context, auditLogType models.AuditLogType, user *models.User, logError error) error {
if l.storageEnabled {
err := l.store(tx, context, auditLogType, user, logError)
if err != nil {
return err
func Detail(key string, value interface{}) DetailOption {
return func(d map[string]interface{}) {
if value != "" || value != nil {
d[key] = value
}
}
}

if l.consoleLoggingEnabled {
l.logToConsole(context, auditLogType, user, logError)
}

return nil
func (l *logger) Create(context echo.Context, auditLogType models.AuditLogType, user *models.User, logError error, detailOpts ...DetailOption) error {
return l.CreateWithConnection(l.persister.GetConnection(), context, auditLogType, user, logError, detailOpts...)
}

func (l *logger) store(tx *pop.Connection, context echo.Context, auditLogType models.AuditLogType, user *models.User, logError error) error {
id, err := uuid.NewV4()
func (l *logger) CreateWithConnection(tx *pop.Connection, context echo.Context, auditLogType models.AuditLogType, user *models.User, logError error, detailOpts ...DetailOption) error {
details := make(map[string]interface{})
for _, detailOpt := range detailOpts {
detailOpt(details)
}

auditLog, err := models.NewAuditLog(auditLogType, l.getRequestMeta(context), details, user, logError)
if err != nil {
return fmt.Errorf("failed to create id: %w", err)
return err
}

al := models.AuditLog{
ID: id,
Type: auditLogType,
Error: nil,
MetaHttpRequestId: context.Response().Header().Get(echo.HeaderXRequestID),
MetaUserAgent: context.Request().UserAgent(),
MetaSourceIp: context.RealIP(),
ActorUserId: nil,
ActorEmail: nil,
if l.mustMask {
auditLog = l.mask(auditLog)
}

if user != nil {
al.ActorUserId = &user.ID
if e := user.Emails.GetPrimary(); e != nil {
al.ActorEmail = &e.Address
if l.storageEnabled {
err = l.store(tx, auditLog)
if err != nil {
return err
}
}
if logError != nil {
// check if error is not nil, because else the string (formatted with fmt.Sprintf) would not be empty but look like this: `%!s(<nil>)`
tmp := fmt.Sprintf("%s", logError)
al.Error = &tmp

if l.consoleLoggingEnabled {
l.logToConsole(auditLog)
}

return l.persister.GetAuditLogPersisterWithConnection(tx).Create(al)
return nil
}

func (l *logger) logToConsole(context echo.Context, auditLogType models.AuditLogType, user *models.User, logError error) {
func (l *logger) store(tx *pop.Connection, auditLog models.AuditLog) error {
return l.persister.GetAuditLogPersisterWithConnection(tx).Create(auditLog)
}

func (l *logger) logToConsole(auditLog models.AuditLog) {
var err string
if auditLog.Error != nil {
err = *auditLog.Error
}

now := time.Now()
loggerEvent := zeroLogger.Log().
Str("audience", "audit").
Str("type", string(auditLogType)).
AnErr("error", logError).
Str("http_request_id", context.Response().Header().Get(echo.HeaderXRequestID)).
Str("source_ip", context.RealIP()).
Str("user_agent", context.Request().UserAgent()).
Str("type", string(auditLog.Type)).
Str("error", err).
Str("http_request_id", auditLog.MetaHttpRequestId).
Str("source_ip", auditLog.MetaSourceIp).
Str("user_agent", auditLog.MetaUserAgent).
Any("details", auditLog.Details).
Str("time", now.Format(time.RFC3339Nano)).
Str("time_unix", strconv.FormatInt(now.Unix(), 10))

if user != nil {
loggerEvent.Str("user_id", user.ID.String())
if e := user.Emails.GetPrimary(); e != nil {
loggerEvent.Str("user_email", e.Address)
if auditLog.ActorUserId != nil {
loggerEvent.Str("user_id", auditLog.ActorUserId.String())
if auditLog.ActorEmail != nil {
loggerEvent.Str("user_email", *auditLog.ActorEmail)
}
}

loggerEvent.Send()
}

func (l *logger) getRequestMeta(c echo.Context) models.RequestMeta {
return models.RequestMeta{
HttpRequestId: c.Response().Header().Get(echo.HeaderXRequestID),
UserAgent: c.Request().UserAgent(),
SourceIp: c.RealIP(),
}
}

func (l *logger) mask(auditLog models.AuditLog) models.AuditLog {
if auditLog.ActorEmail != nil && *auditLog.ActorEmail != "" {
email := utils.MaskEmail(*auditLog.ActorEmail)
auditLog.ActorEmail = &email
}

for key, value := range auditLog.Details {
if key == "username" {
auditLog.Details[key] = utils.MaskUsername(value.(string))
}

if key == "email" {
auditLog.Details[key] = utils.MaskEmail(value.(string))
}
}

return auditLog
}
2 changes: 2 additions & 0 deletions backend/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/teamhanko/hanko/backend/cmd/jwk"
"github.com/teamhanko/hanko/backend/cmd/jwt"
"github.com/teamhanko/hanko/backend/cmd/migrate"
"github.com/teamhanko/hanko/backend/cmd/schema"
"github.com/teamhanko/hanko/backend/cmd/serve"
"github.com/teamhanko/hanko/backend/cmd/siwa"
"github.com/teamhanko/hanko/backend/cmd/user"
Expand All @@ -29,6 +30,7 @@ func NewRootCmd() *cobra.Command {
version.RegisterCommands(cmd)
user.RegisterCommands(cmd)
siwa.RegisterCommands(cmd)
schema.RegisterCommands(cmd)

return cmd
}
Expand Down
74 changes: 74 additions & 0 deletions backend/cmd/schema/json2md.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package schema

import (
"encoding/json"
"errors"
"fmt"
"github.com/invopop/jsonschema"
"github.com/spf13/cobra"
"github.com/teamhanko/hanko/backend/config"
"log"
"os"
"os/exec"
)

func NewJson2MdCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "json2md",
Short: "Generate markdown from JSONSchema",
Run: func(cmd *cobra.Command, args []string) {
r := new(jsonschema.Reflector)
r.DoNotReference = true
if err := r.AddGoComments("github.com/teamhanko/hanko/backend", "./config"); err != nil {
log.Fatal(err)
}

if err := r.AddGoComments("github.com/teamhanko/hanko/backend", "./ee"); err != nil {
log.Fatal(err)
}

s := r.Reflect(&config.Config{})
s.Title = "Config"

data, err := json.MarshalIndent(s, "", " ")
if err != nil {
log.Fatal(err)
}

outPath := "./docs/.generated/config"
if _, err := os.Stat(outPath); errors.Is(err, os.ErrNotExist) {
err := os.MkdirAll(outPath, 0750)
if err != nil {
log.Fatal(err)
}
}

err = os.WriteFile(fmt.Sprintf("%s/hanko.config.json", outPath), data, 0600)
if err != nil {
log.Fatal(err)
}

out, err := exec.Command("npx",
"@adobe/jsonschema2md",
"--input=docs/.generated/config",
"--out=docs/.generated/config/md",
"--schema-extension=config.json",
"--example-format=yaml",
"--header=false",
"--skip=definedinfact",
"--skip=typesection",
"--schema-out=-",
"--properties=format",
"--no-readme=true").
CombinedOutput()

if err != nil {
log.Fatal(err)
}

fmt.Println(string(out))
},
}

return cmd
}
17 changes: 17 additions & 0 deletions backend/cmd/schema/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package schema

import "github.com/spf13/cobra"

func NewSchemaCommand() *cobra.Command {
return &cobra.Command{
Use: "schema",
Short: "JSONSchema related commands",
Long: ``,
}
}

func RegisterCommands(parent *cobra.Command) {
cmd := NewSchemaCommand()
parent.AddCommand(cmd)
cmd.AddCommand(NewJson2MdCommand())
}
Loading
Loading