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

Setup keycloak multifactor authentication #185

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
826f31a
init multifactor authentication setup
hilpitome Apr 26, 2024
a0e37aa
Revert "init multifactor authentication setup"
hilpitome Apr 26, 2024
6b276cd
init multifactor authentication setup
hilpitome Apr 26, 2024
77748e0
Merge branch 'main' of github.com:onaio/fhir-tooling into main
hilpitome Jul 3, 2024
8fbca8b
Merge branch 'main' of github.com:onaio/fhir-tooling into main
hilpitome Jul 16, 2024
aa69893
Merge branch 'main' of github.com:onaio/fhir-tooling into main
hilpitome Jul 17, 2024
6c05a9f
Merge branch 'main' of github.com:onaio/fhir-tooling into main
hilpitome Jul 24, 2024
0b5924b
Merge branch 'main' into setup-keycloak-multifactor-authentication
Lentumunai-Mark Jul 29, 2024
c9ad0b7
Merge branch 'main' into setup-keycloak-multifactor-authentication
Lentumunai-Mark Aug 9, 2024
4c3c9fd
merge main
hilpitome Aug 22, 2024
db206fc
add env.example file
hilpitome Aug 22, 2024
0cb63f8
Merge branch 'main' of github.com:onaio/fhir-tooling into main
hilpitome Aug 22, 2024
8e42f4e
Merge branch 'main' into setup-keycloak-multifactor-authentication
hilpitome Aug 22, 2024
f9dcfcf
Merge branch 'main' of github.com:onaio/fhir-tooling into main
hilpitome Aug 26, 2024
d9f09c1
test otp endpoints
hilpitome Aug 28, 2024
20a3fa4
fix merge conflict
hilpitome Aug 28, 2024
b2955f4
Merge branch 'main' of github.com:onaio/fhir-tooling into main
hilpitome Nov 12, 2024
5c35e30
Merge branch 'main' of github.com:onaio/fhir-tooling into main
hilpitome Nov 27, 2024
2d6067a
get and update otp execution flow
hilpitome Nov 28, 2024
ea1fdfa
Merge branch 'main' into setup-keycloak-multifactor-authentication
hilpitome Nov 29, 2024
08ca95d
refactor variable names
hilpitome Nov 29, 2024
28402f0
Merge branch 'setup-keycloak-multifactor-authentication' of github.co…
hilpitome Nov 29, 2024
37f352c
toggle 2factor auth setting
hilpitome Dec 5, 2024
11e8344
Merge branch 'main' of github.com:onaio/fhir-tooling into main
hilpitome Dec 5, 2024
d988835
Merge branch 'main' into setup-keycloak-multifactor-authentication
hilpitome Dec 5, 2024
0349fee
update link to efsity-cli in README
hilpitome Dec 5, 2024
17df517
fix error with logiging option
hilpitome Dec 10, 2024
5ca1223
Merge branch 'main' into setup-keycloak-multifactor-authentication
hilpitome Jan 23, 2025
ad43f19
use get_keycloak_url function
hilpitome Jan 23, 2025
ff86187
Merge branch 'setup-keycloak-multifactor-authentication' of github.co…
hilpitome Jan 23, 2025
dea95e6
resolve string contact error
hilpitome Jan 23, 2025
31c0881
update keycloak endpoint
hilpitome Jan 23, 2025
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
10 changes: 10 additions & 0 deletions importer/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
client_id=''
client_secret=''
fhir_base_url=''
keycloak_url=''
realm=''
product_access_token=''
username=''
password=''
access_token=''
refresh_token=''
37 changes: 30 additions & 7 deletions importer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import pathlib
from datetime import datetime
import json

import click

Expand All @@ -13,7 +14,7 @@
from importer.request import handle_request
from importer.users import (assign_default_groups_roles, assign_group_roles,
confirm_keycloak_user, confirm_practitioner,
create_roles, create_user, create_user_resources)
create_roles, create_user, create_user_resources, get_keycloak_url)
from importer.utils import (build_mapped_payloads, clean_duplicates,
export_resources_to_csv, read_csv,
read_file_in_chunks)
Expand All @@ -40,6 +41,7 @@
@click.option("--chunk_size", required=False, default=1000000)
@click.option("--resources_count", required=False, default=100)
@click.option("--list_resource_id", required=False)
@click.option("--multifactor_authentication", required=False, is_flag=True)
@click.option(
"--log_level", type=click.Choice(["DEBUG", "INFO", "ERROR"], case_sensitive=False)
)
Expand Down Expand Up @@ -76,18 +78,19 @@ def main(
list_resource_id,
sync,
location_type_coding_system,
multifactor_authentication
):
if log_level == "DEBUG":
logging.basicConfig(
filename="importer.log", encoding="utf-8", level=logging.DEBUG
filename="importer.log", level=logging.DEBUG
)
elif log_level == "INFO":
logging.basicConfig(
filename="importer.log", encoding="utf-8", level=logging.INFO
filename="importer.log", level=logging.INFO
)
elif log_level == "ERROR":
logging.basicConfig(
filename="importer.log", encoding="utf-8", level=logging.ERROR
filename="importer.log", level=logging.ERROR
)
logging.getLogger().addHandler(logging.StreamHandler())

Expand Down Expand Up @@ -118,9 +121,9 @@ def main(

logging.info("Starting csv import...")
json_path = "/".join([dir_path, "json_payloads/"])
resource_list = read_csv(csv_file)

if resource_list:
if csv_file is not None:
resource_list = read_csv(csv_file)
if resource_type == "users":
logging.info("Processing users")
with click.progressbar(
Expand Down Expand Up @@ -293,7 +296,27 @@ def main(
issues.append({"Error": message})
logging.error("Unsupported request!")
else:
logging.error("Empty csv file!")
if multifactor_authentication is not None:
# get details
keycloack_browser_flows_response = handle_request(
"GET",payload = "", url = get_keycloak_url()+"/authentication/flows/browser/executions"
)
target_display_name = "Browser - Conditional OTP"

data = json.loads(keycloack_browser_flows_response[0])
result = next((item for item in data if item["displayName"] == target_display_name), None)
# Enable or disable multifactor authentication with OTP
if(result["requirement"]== "ALTERNATIVE"):
result["requirement"] = "REQUIRED"
else:
result["requirement"] = "ALTERNATIVE"
parsed_payload = json.dumps(result)
update_keycloak_browser_flow_response = handle_request(
"PUT",payload = parsed_payload, url = get_keycloak_url()+"/authentication/flows/browser/executions"
)
logging.info(update_keycloak_browser_flow_response)



if final_response and final_response.text:
logging.info('{ "final-response": ' + final_response.text + "}")
Expand Down
Loading