Skip to content

Commit

Permalink
feat (jans-cli-tui): Authn (#4279)
Browse files Browse the repository at this point in the history
* fix(jans-cli-tui): retake openid configuration if not ready (ref: #4157)

* fix(jans-cli-tui): retake openid config when person auth script enabled/disabled

* feat(jans-cli-tui): default ldap server test

* feat(jans-cli-tui): save and add source ldap server

* feat(jans-cli-tui): delete source ldap server

* fix(jans-cli-tui): set default acr if default is selected on ldap config

* feat(jans-cli-tui): edit custom script acr

* fix(jans-cli-tui): max height of config property list

* fix(jans-cli-tui): code smells
  • Loading branch information
devrimyatar authored Apr 6, 2023
1 parent ee91423 commit 46333b6
Show file tree
Hide file tree
Showing 10 changed files with 498 additions and 101 deletions.
39 changes: 22 additions & 17 deletions jans-cli-tui/cli_tui/cli/config_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,27 @@ def get_request_header(self, headers=None, access_token=None):
ret_val.update(headers)
return ret_val

def get_openid_configuration(self):

try:
response = requests.get(
url = 'https://{}{}'.format(self.idp_host, self.discovery_endpoint),
headers=self.get_request_header({'Accept': 'application/json'}),
verify=self.verify_ssl,
cert=self.mtls_client_cert
)
except Exception as e:
self.cli_logger.error(str(e))
if self.wrapped:
return str(e)

raise ValueError(
self.colored_text("Unable to get OpenID configuration:\n {}".format(str(e)), error_color))

self.openid_configuration = response.json()
self.cli_logger.debug("OpenID Config: %s", self.openid_configuration)

return response

def check_connection(self):
self.cli_logger.debug("Checking connection")
Expand Down Expand Up @@ -448,23 +469,7 @@ def check_connection(self):
write_config()
return response.text

try:
response = requests.get(
url = 'https://{}{}'.format(self.idp_host, self.discovery_endpoint),
headers=self.get_request_header({'Accept': 'application/json'}),
verify=self.verify_ssl,
cert=self.mtls_client_cert
)
except Exception as e:
self.cli_logger.error(str(e))
if self.wrapped:
return str(e)

raise ValueError(
self.colored_text("Unable to get OpenID configuration:\n {}".format(str(e)), error_color))

self.openid_configuration = response.json()
self.cli_logger.debug("OpenID Config: %s", self.openid_configuration)
self.get_openid_configuration()

return True

Expand Down
29 changes: 28 additions & 1 deletion jans-cli-tui/cli_tui/jans_cli_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
sys.exit()

import prompt_toolkit
from prompt_toolkit.eventloop import get_event_loop
from prompt_toolkit.application import Application, get_app_session
from prompt_toolkit.application.current import get_app
from prompt_toolkit.key_binding import KeyBindings
Expand Down Expand Up @@ -197,6 +198,26 @@ def cli_requests(self, args: dict) -> Response:
)
return response


def retreive_openid_configuration(
self,
call_after: Optional[Callable] = None
) -> None:
"""Retreives OpenID configuration via CLI Object"""

self.logger.debug('Retreiving OpenID configuration')

async def coroutine():
self.start_progressing(_("Retireiving OpenID configuration..."))
await get_event_loop().run_in_executor(self.executor, self.cli_object.get_openid_configuration)
self.stop_progressing()
self.logger.debug('OpenID Configuration: {}'.format(self.cli_object.openid_configuration))
if call_after:
call_after()

asyncio.ensure_future(coroutine())


def start_progressing(self, message: Optional[str]="Progressing") -> None:
self.progressing_text = message
self.create_background_task(self.progress_coroutine())
Expand Down Expand Up @@ -602,7 +623,8 @@ def getTitledText(
scrollbar: Optional[bool] = False,
line_numbers: Optional[bool] = False,
lexer: PygmentsLexer = None,
text_type: Optional[str] = 'string'
text_type: Optional[str] = 'string',
jans_list_type: Optional[bool] = False,
) -> AnyContainer:

title += ': '
Expand All @@ -628,9 +650,14 @@ def getTitledText(
ta.window.jans_name = name
ta.window.jans_help = jans_help



v = VSplit([Window(FormattedTextControl(title), width=len(title)+1, style=style, height=height), ta])
v.me = ta

if jans_list_type:
v.jans_list_type = True

return v

def getTitledCheckBoxList(
Expand Down
Loading

0 comments on commit 46333b6

Please sign in to comment.