Skip to content

set_token

Set token helper function. Sets or updates Keycloak token on local machine.

set_token(keycloak_token)

Sets or updates a keycloak token on users local machine.

Source code in dapla_team_cli/auth/services/set_token.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def set_token(keycloak_token: Union[str, None]) -> None:
    """Sets or updates a keycloak token on users local machine."""
    config_folder_path = get_config_folder_path()

    if not keycloak_token:
        keycloak_token = q.text(
            "Please provide a Keycloak token. Please go to https://httpbin-fe.staging-bip-app.ssb.no/anything/bearer to fetch it:"
        ).ask()

    config_file_path = config_folder_path + "/dapla-cli-keycloak-token.json"

    if not os.path.exists(config_folder_path):
        os.makedirs(config_folder_path)

    data = {"keycloak_token": keycloak_token}

    with open(config_file_path, "w", encoding="UTF-8") as f:
        json.dump(data, f)

    console.print("Token was succesfully added.", style=styles["success"])