# SharePoint (Microsoft Graph API) Integration

**Source**: `prototype/src/talentverse/nodes/sharepoint_connector.py`
**Protocol**: HTTP/requests + Microsoft Graph API
**Auth**: OAuth2 with Azure AD (client credentials flow)

### Environment Variables

```env
SHAREPOINT_TENANT_ID=
SHAREPOINT_CLIENT_ID=
SHAREPOINT_CLIENT_SECRET=
SHAREPOINT_SITE_ID=
```

## OAuth2 Token Exchange

```python
def get_access_token(self) -> Optional[str]:
    token_url = f"https://login.microsoftonline.com/{self.tenant_id}/oauth2/v2.0/token"
    token_data = {
        'grant_type': 'client_credentials',
        'client_id': self.client_id,
        'client_secret': self.client_secret,
        'scope': 'https://graph.microsoft.com/.default'
    }
    response = requests.post(token_url, data=token_data)
    if response.status_code == 200:
        self.access_token = response.json()['access_token']
        return self.access_token
```

## Key Operations

### List Folder Contents

```python
def list_folder_contents(self, folder_path: str) -> List[Dict]:
    headers = {"Authorization": f"Bearer {self.access_token}"}
    url = f"https://graph.microsoft.com/v1.0/sites/{self.site_id}/drive/root:/{folder_path}:/children"
    response = requests.get(url, headers=headers)
    return response.json().get('value', [])
```

### Download File

```python
def download_file(self, file_path: str) -> bytes:
    headers = {"Authorization": f"Bearer {self.access_token}"}
    url = f"https://graph.microsoft.com/v1.0/sites/{self.site_id}/drive/root:/{file_path}:/content"
    response = requests.get(url, headers=headers)
    return response.content
```

### Upload File

```python
def upload_file(self, file_path: str, file_data: bytes):
    headers = {
        "Authorization": f"Bearer {self.access_token}",
        "Content-Type": "application/octet-stream"
    }
    url = f"https://graph.microsoft.com/v1.0/sites/{self.site_id}/drive/root:/{file_path}:/content"
    response = requests.put(url, headers=headers, data=file_data)
```

### Delete File

```python
def delete_file(self, file_path: str):
    headers = {"Authorization": f"Bearer {self.access_token}"}
    url = f"https://graph.microsoft.com/v1.0/sites/{self.site_id}/drive/root:/{file_path}"
    response = requests.delete(url, headers=headers)
```

## Employee Folder Structure

```
eDossier/
  {Employee_Name}_{EmployeeID}/
    Documents/
      assessment_rubric/    # Rubric files
    Insights/               # Insight reports
```

```python
def get_employee_folder_path(self, employee_id: str, employee_name: str) -> str:
    folder_name = f"{employee_name}_{employee_id}"
    return f"eDossier/{folder_name}"
```

## Key Notes
- Folders MUST already exist - never auto-create
- File naming: `{Employee_Name}_{Year}_{module}.md`
- Token refresh needed every ~1 hour
- Uses Microsoft Graph API v1.0
