Skip to content

Commit

Permalink
fix Google Drive connector
Browse files Browse the repository at this point in the history
  • Loading branch information
walterbm-cohere committed Dec 4, 2023
1 parent a8180af commit fcd6b14
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions gdrive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ The `GDRIVE_CONNECTOR_API_KEY` should contain an API key for the connector. This

When using OAuth for authentication, the connector does not require any additional environment variables. Instead, the OAuth flow should occur outside of the Connector and Cohere's API will forward the user's access token to this connector through the `Authorization` header.

To use OAuth, you must first create a Google OAuth client ID and secret. You can follow Google's [guide](https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred) to get started. When creating your application use `https://api.cohere.com/v1/connectors/oauth/token` as the redirect URI.

Once your Google OAuth credentials are ready, you can register the connector in Cohere's API with the following configuration:

```bash
curl -X POST \
'https://api.cohere.ai/v1/connectors' \
--header 'Accept: */*' \
--header 'Authorization: Bearer {COHERE-API-KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "GDrive with OAuth",
"url": "{YOUR_CONNECTOR-URL}",
"oauth": {
"client_id": "{GOOGLE-OAUTH-CLIENT-ID}",
"client_secret": "{GOOGLE-OAUTH-CLIENT-SECRET}",
"authorize_url": "https://accounts.google.com/o/oauth2/auth",
"token_url": "https://oauth2.googleapis.com/token",
"scope": "https://www.googleapis.com/auth/drive.readonly"
}
}'
```

With OAuth the connector will be able to search any Google Drive folders that the user has access to.

## Optional Configuration
Expand All @@ -70,8 +93,7 @@ Create a virtual environment and install dependencies with poetry. We recommend
Next, start up the search connector server:

```bash
$ poetry shell
$ flask --app provider --debug run --port 5000
$ poetry flask --app provider --debug run --port 5000
```

and check with curl to see that everything works:
Expand Down
2 changes: 1 addition & 1 deletion gdrive/provider/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ def search(query, access_token=None):
except HttpError as http_error:
raise UpstreamProviderError(message=str(http_error)) from http_error

return process_data_with_service(search_results, request_credentials)
return process_data_with_service(search_results, request_credentials(access_token))

0 comments on commit fcd6b14

Please sign in to comment.