Skip to content

Commit

Permalink
fix OAuth setup, test
Browse files Browse the repository at this point in the history
  • Loading branch information
tianjing-li committed Dec 13, 2023
1 parent 5a55b0b commit cff39ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
12 changes: 9 additions & 3 deletions sharepoint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ Navigate to Applications > App registrations > New registration option.

Select "Web" as the platform, and add a redirect URI as needed. For App auth, you can set the URI to the server you're hosting the connector on. For Delegated auth, set the URI to `https://api.cohere.com/v1/connectors/oauth/token`.

Next, we will configure your App permissions (this requires Admin access on Entra). Head under your app's API permissions page and select Add a permission > Microsoft Graph > Application Permissions > In the Select Permissions dialog, choose `Application.Read.All`.
Next, we will configure your App permissions (this requires Admin access on Entra). Head under your app's API permissions page and select Add a permission > Microsoft Graph. From here, select either Application of Delegated permissions as required, and check the following permissions:

- `offline_access` (only if using Delegated)
- `Application.Read.All`
- `Files.ReadWrite.All` (MSFT requires this to enable search, though this connector will never write anything)

Go back to API permissions, and as an Admin, select Grant admin consent for MSFT.

Then, head to Certificates & Secrets and create a new client secret.

Expand Down Expand Up @@ -77,8 +83,8 @@ Next, register the connector with Cohere's API using the following configuration
"oauth": {
"client_id": "{Your Microsoft App CLIENT-ID}",
"client_secret": "{Your Microsoft App CLIENT-SECRET}",
"authorize_url": "https://login.microsoftonline.com/{Your Microsoft App TENANT-ID}/oauth2/v2.0/authorize"
"token_url": "https://login.microsoftonline.com/{Your Microsoft App TENANT-ID}/oauth2/v2.0/token"
"authorize_url": "https://login.microsoftonline.com/{Your Microsoft App TENANT-ID}/oauth2/v2.0/authorize",
"token_url": "https://login.microsoftonline.com/{Your Microsoft App TENANT-ID}/oauth2/v2.0/token",
"scope": ".default offline_access"
}
}'
Expand Down
24 changes: 12 additions & 12 deletions sharepoint/provider/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ def set_user_access_token(self, token):
self.headers = {"Authorization": f"Bearer {self.access_token}"}

def search(self, query):
request = {
"entityTypes": self.SEARCH_ENTITY_TYPES,
"query": {
"queryString": query,
"size": self.search_limit,
},
}

if self.auth_type == self.APPLICATION_AUTH:
request["region"] = self.DEFAULT_REGION

response = requests.post(
f"{self.BASE_URL}/search/query",
headers={"Authorization": f"Bearer {self.access_token}"},
json={
"requests": [
{
"entityTypes": self.SEARCH_ENTITY_TYPES,
"region": self.DEFAULT_REGION,
"query": {
"queryString": query,
"size": self.search_limit,
},
}
]
},
json={"requests": [request]},
)

if not response.ok:
Expand Down

0 comments on commit cff39ac

Please sign in to comment.