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: [WIP] Implement OIDC sign-in #9251

Draft
wants to merge 224 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 170 commits
Commits
Show all changes
224 commits
Select commit Hold shift + click to select a range
c2c8644
deps(cpan): Install OIDC::Lite
hangy Oct 28, 2023
23cc509
chg: Add sign_in.pl to redirect to OIDC
hangy Oct 28, 2023
77fc76e
chg: Dynamically build URIs
hangy Oct 29, 2023
f1eaf1a
chg: Add dummy OIDC client
hangy Oct 29, 2023
bce027f
chg: Deploy keycloak in dev container
hangy Oct 29, 2023
e964865
dev: Add dev realm to keycloak deployment
hangy Oct 29, 2023
476c5f1
wip: Get userinfo from keycloak
hangy Nov 4, 2023
0f4e6e5
Merge remote-tracking branch 'origin/main' into keycloak
hangy Nov 4, 2023
f1320c9
feat: Implement Resource Owner Password Credentials Grant
hangy Nov 10, 2023
784997c
Update keycloak dev realm
hangy Nov 13, 2023
a52795c
chg: Disable email verification for local dev
hangy Nov 20, 2023
c9ab30d
chg: Store OIDC tokens in session
hangy Nov 20, 2023
2537604
chg: Store token expiration in user session
hangy Nov 20, 2023
b845b49
chg: Switch URL from auth.* to accounts.*
hangy Nov 20, 2023
3b12ab3
feat: Open new session on OIDC callback
hangy Nov 20, 2023
f00ed5c
Merge remote-tracking branch 'origin/main' into keycloak
hangy Nov 20, 2023
de9aad3
feat: Replace custom password reset with redirect to Keycloak
hangy Nov 21, 2023
45572d9
chg: Automatically create user upon OIDC callback
hangy Nov 21, 2023
8decb47
Merge remote-tracking branch 'origin/main' into keycloak
hangy Nov 25, 2023
3312a22
wip: Verification of ID Token
hangy Nov 26, 2023
aaf5de3
refactor: Use new `$BASE_DIRS{USERS}` instead of `$data_root/users`.
hangy Nov 26, 2023
988991b
chg: Verify ID token using newer JWT lib
hangy Nov 26, 2023
2d99146
chg: Attempt to verify Bearer token for the API
hangy Nov 26, 2023
201cb49
refactor: Use new `$BASE_DIRS{USERS}` instead of `$data_root/users`.
hangy Nov 26, 2023
cfb7e15
deps(Docker): Bump keycloak from 22.0.5 to 23.0.0
hangy Nov 27, 2023
df5cf64
chg: Add Hoppscotch for API testing
hangy Nov 27, 2023
ebb1e33
wip: Create users in Keycloak from inside Product Opener for backward…
hangy Nov 27, 2023
c721930
fix: Default $return_url to root of current subdomain
hangy Dec 2, 2023
77e6984
chg: Redirect change_password to keycloak
hangy Dec 2, 2023
6ed8ef6
chg: Use id_token instead userinfo endpoint
hangy Dec 2, 2023
dd20a59
feat: Create user file on API request with token
hangy Dec 2, 2023
7e63735
Merge remote-tracking branch 'origin/main' into keycloak
hangy Dec 2, 2023
9feed4a
chg: Use user_id from id token for API requests
hangy Dec 3, 2023
5a6ac7a
feat: Create Keycloak user via REST API
hangy Dec 5, 2023
6391b32
Merge remote-tracking branch 'origin/main' into keycloak
hangy Dec 5, 2023
9233cd1
chg: Start keycloak for tests, and use more complex password for tests
hangy Dec 6, 2023
6979e1a
chg: Dynamically OIDC data from documents
hangy Dec 6, 2023
e41eb0e
chg: Use location header to get info about created user
hangy Dec 10, 2023
6fc654b
chg: Delete users in Keycloak during tests
hangy Dec 10, 2023
c909190
Merge remote-tracking branch 'origin/main' into keycloak
hangy Dec 10, 2023
1691c7f
test: Use new password in integration tests
hangy Dec 11, 2023
7897fb6
Merge remote-tracking branch 'origin/main' into keycloak
hangy Dec 11, 2023
a00c626
test: Update expected test result
hangy Dec 11, 2023
b6723b3
Merge remote-tracking branch 'origin/main' into keycloak
hangy Dec 12, 2023
9880524
chg: Use `LWP::UserAgent::Plugin::Retry` for manual Keycloak calls
hangy Dec 12, 2023
9562233
Merge remote-tracking branch 'origin/main' into keycloak
hangy Dec 12, 2023
e6054f7
test: Wait for our Keycloak realm to be ready before running integrat…
hangy Dec 12, 2023
f3fd64b
test: Swap order of `wait_application_ready` and `remove_all_users`
hangy Dec 12, 2023
38c0345
Merge branch 'main' into keycloak
hangy Dec 12, 2023
9a8323b
Merge remote-tracking branch 'origin/main' into keycloak
hangy Dec 15, 2023
87b8342
wip: Log client_id in change log
hangy Dec 15, 2023
595a406
Merge branch 'main' into keycloak
hangy Dec 18, 2023
2cde5bd
wip: Verify azp?
hangy Dec 19, 2023
0ed82d9
feat: Start keycloak with devcontainer
hangy Dec 25, 2023
8597ead
fix: Header name is Authorization, not Authentication
hangy Dec 25, 2023
5df9d1d
fix: iss is named issues in OIDC discovery
hangy Dec 25, 2023
2e39264
test: Verify created_by_client and last_modified_by_client
hangy Dec 25, 2023
0f4f40e
feat: Init user session for API request
hangy Dec 25, 2023
06dbe17
test: Fix patch-auth-bad-oauth-token
hangy Dec 25, 2023
e3de534
Merge remote-tracking branch 'upstream/main' into keycloak
hangy Dec 25, 2023
ce75f72
tests: Move wait_application_ready up
hangy Dec 25, 2023
37187c7
Merge remote-tracking branch 'upstream/main' into keycloak
hangy Dec 25, 2023
fdd203a
chg: Store tokens from session in request, to make them available to …
hangy Dec 26, 2023
af511b0
docs: Improve Auth docs a tiny bit
hangy Dec 26, 2023
c3bf43b
Merge remote-tracking branch 'upstream/main' into keycloak
hangy Dec 26, 2023
5e4714e
feat: Write Deprecation and Sunset headers for old login/SSO urls
hangy Dec 29, 2023
e5bf4e4
feat: Require user to be signed in to open user.pl
hangy Dec 29, 2023
fd2b26a
feat: Use oidc-signin for 'sign in' link
hangy Dec 29, 2023
02341a3
feat: Implement single sign-out with Keycloak
hangy Dec 30, 2023
72549af
Revert "feat: Require user to be signed in to open user.pl"
hangy Dec 30, 2023
6c1cf61
chg: Add scrypt module to Keycloak to enable using existing passwords
hangy Jan 6, 2024
c02723f
Merge remote-tracking branch 'origin/main' into keycloak
hangy Jan 6, 2024
6c3f2a5
fix: Use newer version of keycloak-scrypt, which works with Keycloak …
hangy Jan 7, 2024
7402d27
wip: Add user migration script
hangy Jan 7, 2024
8835f69
fix: Use different library for scrypt
hangy Jan 14, 2024
b8a8326
docs: Document more Perl code
hangy Jan 19, 2024
05528fa
docs: Apply suggestions from code review
hangy Jan 19, 2024
b5fde3d
Merge remote-tracking branch 'origin/main' into keycloak
hangy Jan 19, 2024
c618aaf
chg: Use `retrieve_user` to load user file
hangy Jan 19, 2024
a9c912a
docs: Improve docs of OIDC related code.
hangy Jan 19, 2024
3704cab
refactor: Extract get_cookie_domain to sub
hangy Jan 19, 2024
d1389d9
fix: Use preferred_language and country instead of initial_lc and ini…
hangy Jan 19, 2024
1de649b
perf: Reuse existing token until it times out
hangy Jan 20, 2024
0391333
chg: Show error instead of attempting infinite loop if someone might …
hangy Jan 20, 2024
8c7367f
docs: Add perldoc to some Auth subs
hangy Jan 20, 2024
4e52c29
fix: Typo
hangy Jan 20, 2024
36051db
deps: Update Dockerfile.keycloak
hangy Jan 24, 2024
94e1d36
fix: fix docker profile repetition for postgresql container
alexgarel Jan 25, 2024
f1c70d3
Merge branch 'main' into build-docker-profile-postgres
alexgarel Jan 26, 2024
01154d1
feat: Update email handling when dealing with OIDC
hangy Jan 27, 2024
aad2cc1
Merge remote-tracking branch 'origin/main' into keycloak
hangy Jan 27, 2024
3e2b777
Merge remote-tracking branch 'origin/build-docker-profile-postgres' i…
hangy Jan 27, 2024
3308bc6
refactor: Move Keycloak/OIDC settings to ENV vars
hangy Jan 27, 2024
5e74b72
deps: Use pre-built custom Keycloak image
hangy Jan 28, 2024
66281dd
fix: spelling
hangy Jan 28, 2024
bb54f43
fix: Add some stopwords
hangy Jan 28, 2024
32f4eef
fix(test): Add missing import
hangy Jan 28, 2024
dc728b6
feat: Display clientid in product history
hangy Jan 28, 2024
0e1595d
refactor: dashes to underscores
hangy Jan 28, 2024
6f195f1
feat: Try parsing auth header Display
hangy Jan 28, 2024
53cb448
deps: Update Keycloak container from 23.0.4 to 23.0.6
hangy Feb 3, 2024
a580c5d
wip: Import Keycloak users using partial import
hangy Feb 3, 2024
4aefbaf
chg: Import users in more manageable batches
hangy Feb 3, 2024
1797b7b
Merge remote-tracking branch 'origin/main' into keycloak
hangy Feb 3, 2024
d12cbc0
Merge remote-tracking branch 'origin/main' into keycloak
hangy Feb 7, 2024
ca5f24f
fix(tests): Integration tests working on my machine
hangy Feb 7, 2024
9a4c1ef
fix: Merge mistake
hangy Feb 7, 2024
b1bd9f7
test: Add some integration tests for OIDC
hangy Feb 11, 2024
a0d3e9e
Merge remote-tracking branch 'upstream/main' into keycloak
hangy Feb 15, 2024
70dcc26
feat: Remove old login forms but try to keep compatibility, remove po…
hangy Feb 15, 2024
24af950
fix: Update importedApache2::Consts
hangy Feb 16, 2024
541809c
deps: Remove some old CPAN modules and let Keycloak worry babout emai…
hangy Feb 18, 2024
fc50fbc
fix: Partial revert of 70dcc269949d66d230b0ee0c1687c61ec2c93355
hangy Feb 18, 2024
68b8744
fix: Don't overwrite login status
hangy Feb 18, 2024
c6dc534
chg!: Limit fields that can be edited
hangy Feb 18, 2024
7fe580d
refactor: Move Keycloak-specific stuff to dedicated class, so that we…
hangy Mar 2, 2024
b64deba
chg: Check existing mail address from Keycloak instead of users_email…
hangy Mar 2, 2024
6638c50
chg: Deprecate users_emails.sto for existence check
hangy Mar 2, 2024
17b333a
replace try_retrieve_userid_from_mail with is_email_has_off_account
hangy Mar 2, 2024
f79f48d
feat: Pass country / language to login page
hangy Mar 2, 2024
cf3d62a
Merge branch 'main' into keycloak
hangy Mar 4, 2024
bf4e00b
Merge remote-tracking branch 'upstream/main' into keycloak
hangy Mar 7, 2024
7aef570
deps: Update openfoodfacts-auth image
hangy Mar 7, 2024
126f08f
Merge remote-tracking branch 'upstream/main' into keycloak
hangy Mar 9, 2024
59ae976
fix: update test to changes from main
hangy Mar 10, 2024
135c515
wip: Add redis
hangy Mar 13, 2024
82557db
fix: Init and shut down AnyEvent for async stuff
hangy Mar 14, 2024
b590285
Attempt at a redis subscription
hangy Mar 14, 2024
88739f2
Merge branch 'main' into keycloak
hangy Mar 15, 2024
bf42537
Merge remote-tracking branch 'origin/keycloak' into keycloak-redis
hangy Mar 15, 2024
1fdabca
Merge remote-tracking branch 'origin/main' into keycloak
hangy Mar 18, 2024
3ed42ab
Merge branch 'keycloak' into keycloak-redis
hangy Mar 18, 2024
cb80395
Add redis-listener service to docker-compose.yml and prod.yml
hangy Mar 18, 2024
acc6b7c
deps: Update openfoodfacts-auth image
hangy Mar 19, 2024
7f1ae34
dev: Update container deps
hangy Mar 20, 2024
f8394a6
wip: Read from stream
hangy Mar 20, 2024
bf28080
Merge remote-tracking branch 'origin/main' into keycloak
john-gom Mar 24, 2024
aa282e7
Merge remote-tracking branch 'origin/keycloak' into keycloak-redis
hangy Mar 24, 2024
c813c17
feat: Create Minion task from deleted user Redis event
hangy Mar 25, 2024
172db00
Merge remote-tracking branch 'origin/main' into keycloak
hangy Mar 25, 2024
823df66
fix: `$lang` => `$lc`
hangy Mar 26, 2024
2731b43
Merge remote-tracking branch 'origin/main' into keycloak
hangy Mar 27, 2024
86dccbb
fix: Add missing import
hangy Mar 28, 2024
aaf6137
Merge remote-tracking branch 'origin/main' into keycloak
hangy Mar 28, 2024
d5258dd
feat: Remove user deletion from user.pl
hangy Mar 28, 2024
56181ae
fix: Correct `use` statements
hangy Mar 30, 2024
e0e18f2
Merge remote-tracking branch 'origin/main' into keycloak
hangy Apr 3, 2024
5bf4e8c
dev: Update container deps
hangy Apr 3, 2024
234fe7a
fix: POD for Keycloak/Auth module
hangy Apr 3, 2024
247229b
fix: Update integration tests
hangy Apr 3, 2024
e92569b
fix: Only write old users_emails if it exists already
hangy Apr 4, 2024
cd5293f
Fix email retrieval bug and add new user authentication tests
hangy Apr 6, 2024
5c740a6
Merge remote-tracking branch 'origin/main' into keycloak
hangy Apr 6, 2024
2b773d5
fix: Use preferred username as display name
hangy Apr 7, 2024
f392ea9
fix: Always store emails
hangy Apr 7, 2024
ab420c3
feat: Pass `ui_locales` to Keycloak
hangy Apr 7, 2024
7dc9a57
chg: Accept all mail addresses
hangy Apr 7, 2024
e4b7347
Depreacte `users_emails.sto`
hangy Apr 7, 2024
a2ea550
Refactor email account retrieval and creation in Keycloak
hangy Apr 7, 2024
4bc21f9
fix: Support $request_ref in more places
hangy Apr 13, 2024
754bfff
Merge remote-tracking branch 'origin/main' into keycloak
hangy Apr 13, 2024
f0a176f
dev: Update container deps
hangy Apr 21, 2024
66a7fdd
fix: Expose keycloak behind proxy to reenable discovery
hangy May 5, 2024
c027498
Merge remote-tracking branch 'origin/main' into keycloak
hangy May 5, 2024
b9625bf
fix: s/auth.openfoodfacts.localhost:8080/auth.openfoodfacts.localhost/
hangy May 5, 2024
1b8b39b
User migration
hangy May 5, 2024
94fd78d
dev: Update env vars after tests with actual reverse proxy on https:/…
hangy May 5, 2024
183f225
Pull keycloak dependency from a separate project
john-gom May 6, 2024
a2d56cb
Fix one test
john-gom May 6, 2024
a6a333f
Forgot to add deps as a dependency
john-gom May 6, 2024
d004b75
Remove env vars no longer needed
john-gom May 10, 2024
0938955
Tests are still responsible for creating their own dependencies
john-gom May 10, 2024
1db9f6e
Merge branch 'main' into keycloak
john-gom May 10, 2024
4ea0389
Merge remote-tracking branch 'origin/main' into keycloak
hangy May 27, 2024
48fc609
Merge remote-tracking branch 'origin/main' into keycloak
hangy Jun 21, 2024
20c718b
Fix deps
john-gom Jun 25, 2024
d0251b9
Restore removed translations
john-gom Jun 25, 2024
302dfef
Fetch keycloak compose from off-auth repo
john-gom Jun 26, 2024
16b2746
Update test results
john-gom Jun 26, 2024
90f2521
Add keycloak health dependency for integration tests
john-gom Jun 28, 2024
de411ec
Use integration-test compose for test stop
john-gom Jun 28, 2024
cf6e0aa
Remove redundant code from update_tests_results
john-gom Jun 28, 2024
eafb82c
Remove unnecessary vars
john-gom Jul 5, 2024
e7d687a
chore: Add redis-listener service to docker run configuration
hangy Jul 7, 2024
100ec40
Merge remote-tracking branch 'origin/main' into keycloak
hangy Jul 7, 2024
100fb64
chore: Ignore deps when building container images
hangy Jul 7, 2024
d18c0a2
fix: Adopt d9d9a70872e443e6c7e5f6f2982f3dccc660921c
hangy Jul 7, 2024
a5810ab
build(deps-dev): Add `UUID` module
hangy Jul 14, 2024
1d45efd
text: Update expected integration test results
hangy Jul 14, 2024
bda3882
Merge remote-tracking branch 'origin/main' into keycloak
hangy Jul 14, 2024
466b6e7
test: Update expected integration test results
hangy Jul 14, 2024
4e71747
Merge remote-tracking branch 'origin/cpan-uuid' into keycloak
hangy Jul 20, 2024
16d407e
Merge remote-tracking branch 'origin/main' into keycloak
hangy Jul 20, 2024
3e36d45
test: Update expected test results after latest merge
hangy Jul 21, 2024
5c2ba8b
Merge remote-tracking branch 'origin/main' into keycloak
hangy Jul 25, 2024
f6306b3
style: Lint perl. Sorry!
hangy Jul 26, 2024
9fda250
refactor: Move Minion methods to separate module
hangy Jul 27, 2024
3f64b82
test: Manually ensure that user deletion from Redis causes Minion job…
hangy Jul 27, 2024
df355e2
test: refactor delete_user.t to depend on less external events
hangy Jul 27, 2024
a7a2165
Merge remote-tracking branch 'origin/main' into keycloak
hangy Jul 27, 2024
b0d675c
refactor: Separate front- and backchannel URL for Keyclaok
hangy Jul 27, 2024
492cdc4
Merge remote-tracking branch 'origin/main' into keycloak
hangy Aug 8, 2024
4d0ba00
Merge branch 'main' into keycloak
hangy Aug 12, 2024
f5bb6a7
feat: Move keycloak account link from user page to dropdown menu
hangy Aug 17, 2024
4e0b65b
Merge remote-tracking branch 'origin/main' into keycloak
hangy Aug 17, 2024
32c4000
test: Update tests results
Aug 17, 2024
9d4061f
Merge remote-tracking branch 'origin/main' into keycloak
hangy Aug 30, 2024
a3de4e9
test: Update tests results
Aug 30, 2024
f785606
refactor: Update keycloak account link generation
hangy Sep 8, 2024
cbe5fe5
test: Update tests results
hangy Sep 8, 2024
54ff395
chg: Add import timestamp
hangy Sep 15, 2024
389d8a8
feat: Add anonymization option for user migration script
hangy Sep 15, 2024
57f835a
Merge branch 'main' into keycloak
hangy Sep 15, 2024
e852eab
fix: fix unit tests
raphael0202 Sep 17, 2024
aa0b56d
Merge remote-tracking branch 'hangy/main' into keycloak
hangy Sep 17, 2024
bb9d25e
Merge remote-tracking branch 'hangy/main' into keycloak
hangy Sep 19, 2024
7115cec
test: Update test results after template changes
hangy Sep 19, 2024
be4a668
test: Run API test with fresh UA each time, and randomize API test ex…
hangy Sep 20, 2024
36e27b1
wip: Add tasks to handle welcoming users and registering them to the …
hangy Sep 23, 2024
839c21a
Revert "test: Run API test with fresh UA each time, and randomize API…
hangy Sep 25, 2024
8c1cee6
fix: Syntax issues
hangy Sep 25, 2024
7d36b09
fix(tests): Run some API tests with fresh UA
hangy Sep 25, 2024
976127e
Add support for SSL in local development
john-gom Sep 27, 2024
e0e05bf
Revert "Add support for SSL in local development"
john-gom Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"frontend",
"incron",
"minion",
"redis"
"redis",
"redis-listener",
"keycloak"
],
"workspaceFolder": "/opt/product-opener",
"customizations": {
Expand Down
17 changes: 15 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ FACETS_KP_URL = https://facets-kp.openfoodfacts.org/render-to-html
# we push updated products to Redis stream so that every service is notified
# when a product is updated/deleted/created
# use `redis:6379` locally if you want to enable Redis
REDIS_URL=
REDIS_URL=redis:6379
GOOGLE_CLOUD_VISION_API_KEY=
CROWDIN_PROJECT_IDENTIFIER=
CROWDIN_PROJECT_KEY=
Expand All @@ -64,4 +64,17 @@ ELASTICSEARCH_HOSTS=
LOG_LEVEL_ROOT=TRACE
LOG_LEVEL_MONGODB=TRACE

BUILD_CACHE_REPO=openfoodfacts/openfoodfacts-build-cache
KEYCLOAK_ADMIN=root
KEYCLOAK_ADMIN_PASSWORD=test
KEYCLOAK_BASE_URL=http://auth.openfoodfacts.localhost:5600
KEYCLOAK_REALM_NAME=open-products-facts
KEYCLOAK_EXPOSE_PORT=5600
KC_HOSTNAME_URL=http://auth.openfoodfacts.localhost:5600
KC_HOSTNAME_ADMIN_URL=http://auth.openfoodfacts.localhost:5600
KC_PROXY_HEADERS=xforwarded

PRODUCT_OPENER_OIDC_CLIENT_ID=ProductOpener
PRODUCT_OPENER_OIDC_CLIENT_SECRET=Cf4NdSAjZsNO9HLcuXeuvukzFu00roQa
PRODUCT_OPENER_OIDC_DISCOVERY_ENDPOINT=http://auth.openfoodfacts.localhost:5600/realms/open-products-facts/.well-known/openid-configuration

BUILD_CACHE_REPO=openfoodfacts/openfoodfacts-build-cache
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ nytprof*.out
# Local databases
data/mongodb
Lang.open*
users_emails.sto
html/data/*
html/products_countries.js
products_stats_*.html
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt set -x && \
libcache-memcached-fast-perl \
libjson-pp-perl \
libclone-perl \
libcrypt-passwdmd5-perl \
libencode-detect-perl \
libgraphics-color-perl \
libbarcode-zbar-perl \
Expand All @@ -67,6 +66,7 @@ RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt set -x && \
libdbd-pg-perl \
libtemplate-perl \
liburi-escape-xs-perl \
libanyevent-redis-perl \
# NB: not available in ubuntu 1804 LTS:
libmath-random-secure-perl \
libfile-copy-recursive-perl \
Expand All @@ -78,8 +78,7 @@ RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt set -x && \
liblog-log4perl-perl \
liblog-any-adapter-log4perl-perl \
# NB: not available in ubuntu 1804 LTS:
libgeoip2-perl \
libemail-valid-perl
libgeoip2-perl
RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt set -x && \
apt install -y \
#
Expand Down Expand Up @@ -158,6 +157,8 @@ RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt set -x && \
libperl-dev \
# needed to build Apache2::Connection::XForwardedFor
libapache2-mod-perl2-dev \
# OpenSSL dev needed by OIDC::Lite
libssl-dev \
# Imager::zxing - build deps
cmake \
pkg-config \
Expand Down
19 changes: 14 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ build:
@echo "🥫 Building containers …"
${DOCKER_COMPOSE} build ${args} ${container} 2>&1

_up:
_up: deps
@echo "🥫 Starting containers …"
${DOCKER_COMPOSE} up -d 2>&1
@echo "🥫 started service at http://openfoodfacts.localhost"
Expand Down Expand Up @@ -255,7 +255,7 @@ checks: front_build front_lint check_perltidy check_perl_fast check_critic check

lint: lint_perltidy lint_taxonomies

tests: build_taxonomies_test build_lang_test unit_test integration_test
tests: deps build_taxonomies_test build_lang_test unit_test integration_test

# add COVER_OPTS='-e HARNESS_PERL_SWITCHES="-MDevel::Cover"' if you want to trigger code coverage report generation
unit_test: create_folders
Expand All @@ -270,7 +270,7 @@ integration_test: create_folders
# we launch the server and run tests within same container
# we also need dynamicfront for some assets to exists
# this is the place where variables are important
${DOCKER_COMPOSE_INT_TEST} up -d memcached postgres mongodb backend dynamicfront incron minion redis
${DOCKER_COMPOSE_INT_TEST} up -d memcached postgres mongodb backend dynamicfront incron minion redis redis-listener frontend
# note: we need the -T option for ci (non tty environment)
${DOCKER_COMPOSE_INT_TEST} exec ${COVER_OPTS} -e PO_EAGER_LOAD_DATA=1 -T backend yath -PProductOpener::LoadData tests/integration
${DOCKER_COMPOSE_INT_TEST} stop
Expand All @@ -295,7 +295,7 @@ test-unit: guard-test create_folders
# you can also add args= to pass more options to your test command
test-int: guard-test create_folders
@echo "🥫 Running test: 'tests/integration/${test}' …"
${DOCKER_COMPOSE_INT_TEST} up -d memcached postgres mongodb backend dynamicfront incron minion redis
${DOCKER_COMPOSE_INT_TEST} up -d memcached postgres mongodb backend dynamicfront incron minion redis redis-listener frontend
${DOCKER_COMPOSE_INT_TEST} exec -e PO_EAGER_LOAD_DATA=1 backend ${TEST_CMD} ${args} tests/integration/${test}
# better shutdown, for if we do a modification of the code, we need a restart
${DOCKER_COMPOSE_INT_TEST} stop backend
Expand All @@ -310,7 +310,7 @@ clean_tests:

update_tests_results: build_taxonomies_test build_lang_test
@echo "🥫 Updated expected test results with actuals for easy Git diff"
${DOCKER_COMPOSE_TEST} up -d memcached postgres mongodb backend dynamicfront incron
${DOCKER_COMPOSE_TEST} up -d memcached postgres mongodb backend dynamicfront incron redis redis-listener keycloak redis redis-listener frontend
${DOCKER_COMPOSE_TEST} run --no-deps --rm -e GITHUB_TOKEN=${GITHUB_TOKEN} backend /opt/product-opener/scripts/taxonomies/build_tags_taxonomy.pl ${name}
${DOCKER_COMPOSE_TEST} run --rm backend perl -I/opt/product-opener/lib -I/opt/perl/local/lib/perl5 /opt/product-opener/scripts/build_lang.pl
${DOCKER_COMPOSE_TEST} exec -T -w /opt/product-opener/tests backend bash update_tests_results.sh
Expand Down Expand Up @@ -494,3 +494,12 @@ guard-%: # guard clause for targets that require an environment variable (usuall
exit 1; \
fi;

# Load dependent projects
deps:
@for dep in "openfoodfacts-auth" ; do \
if [ ! -d ../$$dep ]; then \
git clone --filter=blob:none --sparse \
https://github.com/openfoodfacts/$$dep.git ../$$dep; \
fi; \
cd ../$$dep && make -e run; \
done
1 change: 1 addition & 0 deletions cgi/auth.pl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use ProductOpener::Users qw/$User_id %User is_admin_user/;
use ProductOpener::Lang qw/:all/;
use ProductOpener::Tags qw/country_to_cc/;
use ProductOpener::Auth qw/write_auth_deprecated_headers/;

use Apache2::Const -compile => qw(OK);
use CGI qw/:cgi :form escapeHTML/;
Expand Down
77 changes: 8 additions & 69 deletions cgi/change_password.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This file is part of Product Opener.
#
# Product Opener
# Copyright (C) 2011-2023 Association Open Food Facts
# Copyright (C) 2011-2024 Association Open Food Facts
# Contact: [email protected]
# Address: 21 rue des Iles, 94100 Saint-Maur des Fossés, France
#
Expand All @@ -25,78 +25,17 @@
use CGI::Carp qw(fatalsToBrowser);

use ProductOpener::Config qw/:all/;
use ProductOpener::Paths qw/:all/;
use ProductOpener::Store qw/:all/;
use ProductOpener::Display qw/$tt display_page init_request process_template single_param/;
use ProductOpener::Users qw/$User_id check_password_hash create_password_hash retrieve_user store_user/;
use ProductOpener::Lang qw/lang/;
use ProductOpener::Display qw/init_request display_error_and_exit redirect_to_url/;

use Apache2::Const -compile => qw(OK);
use CGI qw/:cgi :form escapeHTML/;
use URI::Escape::XS;
use Encode;
use Log::Any qw($log);
use URI::Escape::XS qw/uri_escape/;

my $request_ref = ProductOpener::Display::init_request();

my $template_data_ref = {method => $ENV{'REQUEST_METHOD'}};

$log->info('start') if $log->is_info();
if (not defined $User_id) {
my $r = shift;
$r->headers_out->set(Location => '/cgi/login.pl?redirect=/cgi/change_password.pl');
$r->status(307);
return Apache2::Const::OK;
unless ((defined $oidc_options{keycloak_base_url}) and (defined $oidc_options{keycloak_realm_name})) {
display_error_and_exit($request_ref, 'File not found.', 404);
}

my @errors = ();

if ($ENV{'REQUEST_METHOD'} eq 'POST') {
# TODO: This will change for Keycloak
my $user_ref = retrieve_user($User_id);
if (not(defined $user_ref)) {
push @errors, 'undefined user';
$template_data_ref->{success} = 0;
}

my $hash_is_correct = check_password_hash(encode_utf8(decode utf8 => single_param('current_password')),
$user_ref->{'encrypted_password'});

# We don't have the right password
if (not $hash_is_correct) {
$log->info(
'bad password - input does not match stored hash',
{encrypted_password => $user_ref->{'encrypted_password'}}
) if $log->is_info();
push @errors, lang('error_bad_login_password');
}

if (length(single_param('password')) < 6) {
push @errors, lang('error_invalid_password');
}

if ((single_param('password')) ne (single_param('confirm_password'))) {
push @errors, lang('error_different_passwords');
}

if (scalar(@errors) > 0) {
$template_data_ref->{success} = 0;
}
else {
$user_ref->{encrypted_password} = create_password_hash(encode_utf8(decode utf8 => single_param('password')));
store_user($user_ref);
$template_data_ref->{success} = 1;
}
}

$template_data_ref->{errors} = \@errors;

my $html;
process_template('web/pages/change_password/change_password.tt.html', $template_data_ref, \$html) or $html = '';
if ($tt->error()) {
$html .= '<p>' . $tt->error() . '</p>';
}
my $redirect
= $oidc_options{keycloak_base_url} . '/admin/realms/' . uri_escape($oidc_options{keycloak_realm_name}) . '/users';

$request_ref->{title} = lang('change_password');
$request_ref->{content_ref} = \$html;
display_page($request_ref);
redirect_to_url($request_ref, 302, $redirect);
74 changes: 29 additions & 45 deletions cgi/login.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This file is part of Product Opener.
#
# Product Opener
# Copyright (C) 2011-2023 Association Open Food Facts
# Copyright (C) 2011-2024 Association Open Food Facts
# Contact: [email protected]
# Address: 21 rue des Iles, 94100 Saint-Maur des Fossés, France
#
Expand All @@ -28,71 +28,55 @@
use ProductOpener::Paths qw/:all/;
use ProductOpener::Store qw/:all/;
use ProductOpener::Display qw/:all/;
use ProductOpener::Users qw/$User_id check_password_hash retrieve_user/;
use ProductOpener::Users qw/$User_id retrieve_user/;
use ProductOpener::Lang qw/lang/;
use ProductOpener::Auth qw/password_signin access_to_protected_resource/;

use Apache2::Const -compile => qw(OK);
use Apache2::Const -compile => qw/OK :http/;
use CGI qw/:cgi :form escapeHTML/;
use URI::Escape::XS;
use Encode;
use Log::Any qw($log);

my $request_ref = ProductOpener::Display::init_request();

my $template_data_ref = {};

$log->info('start') if $log->is_info();

my $r = shift;
my $redirect = single_param('redirect');
$template_data_ref->{redirect} = $redirect;
my $loc = $redirect || $formatted_subdomain . "/cgi/session.pl";
my $status_code = Apache2::Const::HTTP_BAD_REQUEST;
my $final_status_set = 0;
if (defined $User_id) {
my $loc = $redirect || $formatted_subdomain . "/cgi/session.pl";
# User is already signed in via cookie or similar, as determined by init_request.
$r->headers_out->set(Location => $loc);
$r->err_headers_out->add('Set-Cookie' => $request_ref->{cookie});
$r->status(302);
return Apache2::Const::OK;
$status_code = Apache2::Const::HTTP_MOVED_TEMPORARILY;
$final_status_set = 1;
}

my @errors = ();

if ($ENV{'REQUEST_METHOD'} eq 'POST') {
my $user_ref = retrieve_user($User_id);
if (not(defined $user_ref)) {
push @errors, 'undefined user';
$template_data_ref->{success} = 0;
}

my $hash_is_correct
= check_password_hash(encode_utf8(decode utf8 => single_param('password')), $user_ref->{'encrypted_password'});

# We don't have the right password
if (not $hash_is_correct) {
$log->info(
'bad password - input does not match stored hash',
{encrypted_password => $user_ref->{'encrypted_password'}}
) if $log->is_info();
push @errors, lang('error_bad_login_password');
}
if (not($final_status_set) and (not($ENV{'REQUEST_METHOD'} eq 'POST'))) {
# After OIDC/Keycloak integration, the original login form is no longer used.
# However, some external sites (ie. Hunger Games) may still be using it.
$request_ref->{return_url} = single_param('redirect');
access_to_protected_resource($request_ref);
$final_status_set = 1;
}

if (scalar(@errors) > 0) {
$template_data_ref->{success} = 0;
if (not($final_status_set)) {
my ($oidc_user_id, $refresh_token, $refresh_expires_at, $access_token, $access_expires_at, $id_token)
= password_signin(encode_utf8(decode utf8 => single_param('user_id')),
encode_utf8(decode utf8 => single_param('password')));
if ($oidc_user_id) {
$r->headers_out->set(Location => $loc);
$status_code = Apache2::Const::HTTP_MOVED_TEMPORARILY;
}
else {
$template_data_ref->{success} = 1;
$status_code = Apache2::Const::HTTP_UNAUTHORIZED;
}
}

$template_data_ref->{errors} = \@errors;

# Display the sign in form
my $html;
process_template('web/pages/session/sign_in_form.tt.html', $template_data_ref, \$html) or $html = '';
if ($tt->error()) {
$html .= '<p>' . $tt->error() . '</p>';
$final_status_set = 1;
}

$request_ref->{title} = lang('login_register_title');
$request_ref->{content_ref} = \$html;
display_page($request_ref);

$r->err_headers_out->add('Set-Cookie' => $request_ref->{cookie});
$r->status($status_code);
return Apache2::Const::OK;
Loading
Loading