Skip to content

Need to parse and return a consistent response from keycloak proxy #420

@longshuicy

Description

@longshuicy

Right now we commented out the below because this performs differently for backend in docker container vs backend as it is:

@router.get("/broker/{identity_provider}/token")
def get_idenity_provider_token(
    identity_provider: str, access_token: str = Security(oauth2_scheme)
) -> Json:
    """Get identity provider JWT token from keyclok. Keycloak must be configured to store external tokens."""
    if identity_provider in settings.keycloak_ipds:
        idp_url = f"{settings.auth_base}/auth/realms/{settings.auth_realm}/broker/{identity_provider}/token"
        idp_headers = {
            "Content-Type": "application/x-www-form-urlencoded",
            "Authorization": f"Bearer {access_token}",
        }
        idp_token = requests.request("GET", idp_url, headers=idp_headers)
        # FIXME is there a better way to know if the token as expired and the above call did not go through?
        idp_token.raise_for_status()
        itp_token_body = json.loads(idp_token.content)
        return itp_token_body
    else:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail={
                "error_msg": f"Identy provider [{identity_provider}] not recognized."
            },
            headers={"WWW-Authenticate": "Bearer"},
        )

Originally posted by @lmarini in #396 (comment)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions