Redirect in after a login page

I’ve used aws to handle user authentication on my deployed app see below function

# -------------------------------------------------------
# Use authorization code to get user access and id tokens
# -------------------------------------------------------
def get_user_tokens(auth_code):
    """
    Gets user tokens by making a post request call.

    Args:
        auth_code: Authorization code from cognito server.

    Returns:
        {
        'access_token': access token from cognito server if user is successfully authenticated.
        'id_token': access token from cognito server if user is successfully authenticated.
        }

    """

    token_url = f"{COGNITO_DOMAIN}/oauth2/token"
    client_secret_string = f"{CLIENT_ID}:{CLIENT_SECRET}"
    client_secret_encoded = str(
        base64.b64encode(client_secret_string.encode("utf-8")), "utf-8"
    )
    headers = {
        "Content-Type": "application/x-www-form-urlencoded",
        "Authorization": f"Basic {client_secret_encoded}",
    }
    body = {
        "grant_type": "authorization_code",
        "client_id": CLIENT_ID,
        "code": auth_code,
        "redirect_uri": APP_URI,
    }
    print(token_url)
    token_response = requests.post(token_url, headers=headers, data=body)
    try:
        access_token = token_response.json()["access_token"]
        id_token = token_response.json()["id_token"]
    except (KeyError, TypeError):
        access_token = ""
        id_token = ""

    return access_token, id_token

Issue is that when I click on this in the current deployed version is shows refused to connect but on my local version this workflow is working,

Also, weirdly it works if I open on a new tab, yet the url is the developer one and when I try to open it elsewhere it says I need the github credentials which obviousy won’t work for other users.

Anyone know why it works on my local version but not on the deployed app?

Here’s the code that is causing the issue for greater context

session = boto3.Session(
    aws_access_key_id= os.getenv('AWS_ACCESS_KEY_ID'),
    aws_secret_access_key= os.getenv('AWS_SECRET_ACCESS_KEY'),
    region_name='eu-north-1'
)
s3_client = boto3.client('s3')

s3 = session.resource('s3')

authenticate.set_st_state_vars()

if st.session_state["authenticated"]:
    authenticate.button_logout()
else:
![Screenshot 2023-10-16 at 20.46.51|690x267](upload://5NPbIr9EwuCuTGogdsGtI1odx6G.png)

    authenticate.button_login()```

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.