How to add an OAuth Custom in an external API with GPTs?

Hello, I am making a GPT and I need to use OAuth to login in an external app with information about employees.


1
2


When I push the button am redirected, but get this error:
3

Code:

from fastapi.responses import HTMLResponse
from fastapi import Request

@app.get("/")
async def login_for_access_token(request:Request):
    print(request.query_params)
    return HTMLResponse(content="""
    <!DOCTYPE html>
    <html>
        <head>
            <title>FastAPI HTML Example</title>
            <script>
                function redirectToOAuth() {
                    const tokenData = {
                        access_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
                        token_type: "bearer",
                        refresh_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36Padw324sw5c",
                        expires_in: 59
                    };
                    const url = new URL('https://chat.openai.com/aip/_______/oauth/callback');
                    Object.keys(tokenData).forEach(key => url.searchParams.append(key, tokenData[key]));
                    url.searchParams.append('state', 'adsadsadg342')
                    window.location.href = url;
                }
            </script>
        </head>
        <body>
            <h1>API de base de datos de empresa</h1>
            <p>Esta es una página HTML simple servida por FastAPI.</p>
            <button onclick="redirectToOAuth()">Redirigir</button>
        </body>
    </html>
    """, status_code=200)

I am new in OAuth and I don’t know what I am doing wrong.

Thank you.

Hi

I use the OpenAI API and am not familiar with GPT. Have you thought of using the API? you get a lot more flexibility in calling your own functions with function calling, customizing prompts depending on the authorizations status of the users, etc.

Am not sure if GPT will support all that you are trying to do with the auth.

Hello, It supports oauth 2, I would use OpenAI API, but a customer want a GPT to beggining in his business cause it is cheaper than a website with an API, after some time will suggest him to change in Assistants API.