openai/plugins-quickstart

redirect_uri mismatch error when I try authenticate with Google

feargswalsh92 opened this issue · 1 comments

I've set up my plugin on Google Cloud Platform but no matter what values I set in the dashboard or code for the redirect_uri I get the same error

You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy.

If you're the app developer, register the redirect URI in the Google Cloud Console.
Request details: redirect_uri=http://localhost:8080/
image

I originially set the redirect_uri to an ngrok domain, that I pointed at my local port 5003. Then I realized that the flow app was setting the redirect_uri in it's domain as 8080 by default

Does anyone know if there's a particular redirect_uri I should be using to work with Chatgpt based plugins? Here's my code but take it with a pinch of salt with regards the port configurations, as I've tried every variation I can think of to no avail.

import json

import quart
import quart_cors
from quart import request

from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build

app = quart_cors.cors(quart.Quart(__name__), allow_origin="https://chat.openai.com")

@app.get("/logo.png")
async def plugin_logo():
    filename = 'logo.png'
    return await quart.send_file(filename, mimetype='image/png')

@app.get("/.well-known/ai-plugin.json")
async def plugin_manifest():
    host = request.headers['Host']
    with open("./.well-known/ai-plugin.json") as f:
        text = f.read()
        return quart.Response(text, mimetype="text/json")

@app.get("/openapi.yaml")
async def openapi_spec():
    host = request.headers['Host']
    with open("openapi.yaml") as f:
        text = f.read()
        return quart.Response(text, mimetype="text/yaml")

# The scope required to modify Google Calendar
SCOPES = ['https://www.googleapis.com/auth/calendar.events']

def authenticate_and_get_service():
    flow = InstalledAppFlow.from_client_secrets_file('client_secrets.json', SCOPES, redirect_uri="http://localhost:8080")

    # This will prompt the user's browser to open a Google login screen
    # After logging in and approving access, the user will be redirected to a local server
    # The server will get the authorization code from the response and continue the flow
    creds = flow.run_local_server()
    
    # With the credentials, we can build the service
    service = build('calendar', 'v3', credentials=creds)
    
    return service

@app.route("/create-calendar-event", methods=['POST'])
async def create_calendar_event():
    # Get the event details from the request
    # event_details = await request.get_json()

    # Authenticate and get the Google Calendar service
    service = authenticate_and_get_service()

    # Now you can use the service object to create a calendar event
    # You will need to implement the create_event function
    # This function should use the Google Calendar API to create an event with the provided details
    # create_event(service, event_details)

    return quart.Response("Event created successfully", status=200)

def main():
    app.run(debug=True, host="0.0.0.0", port=8080)

# Now you can use the service object to interact with the Google Calendar API

if __name__ == "__main__":
    main()

I was missing a trailing slash I believe