function test_tenant_admin_center_approach
Displays detailed troubleshooting instructions for resolving SharePoint 'Unsupported app only token' errors by providing three alternative configuration approaches through tenant admin center.
/tf/active/vicechatdev/SPFCsync/diagnose_permissions.py
25 - 68
simple
Purpose
This diagnostic function helps administrators resolve SharePoint authentication issues when app-only tokens are not supported. It extracts tenant information from configuration, generates specific URLs for the tenant's admin center, and provides step-by-step instructions for three different methods: SharePoint Admin Center, API Management, and PowerShell. The function is designed to guide users through enabling app-only authentication in SharePoint Online environments.
Source Code
def test_tenant_admin_center_approach():
"""Provide instructions for tenant admin center approach."""
config = load_config()
if not config:
return
site_url = config.get('SHAREPOINT_SITE_URL', '')
client_id = config.get('AZURE_CLIENT_ID', '')
if '.sharepoint.com' in site_url:
tenant = site_url.split('.sharepoint.com')[0].split('https://')[-1]
else:
print("❌ Cannot extract tenant from SharePoint URL")
return
print("🔧 Tenant Admin Center Approach")
print("=" * 40)
print("The 'Unsupported app only token' error suggests your SharePoint")
print("tenant might not allow app-only tokens by default.")
print()
print("Try this alternative approach:")
print()
print("1. **SharePoint Admin Center Method:**")
admin_url = f"https://{tenant}-admin.sharepoint.com"
print(f" a) Go to: {admin_url}")
print(" b) Navigate to: More features → Apps → App Catalog")
print(" c) If no App Catalog exists, create one")
print(" d) Go to 'Apps for SharePoint' → New → Upload")
print(" e) Upload a dummy .sppkg file or use 'Distribute apps using the app catalog'")
print()
print("2. **API Management Method:**")
api_management_url = f"https://{tenant}-admin.sharepoint.com/_layouts/15/online/AdminHome.aspx#/webApiPermissionManagement"
print(f" a) Go to: {api_management_url}")
print(" b) Look for 'API Management'")
print(" c) Add API permission request:")
print(f" - Resource: Microsoft Graph")
print(f" - Permission: Sites.Read.All")
print(f" - Client ID: {client_id}")
print(" d) Approve the request")
print()
print("3. **PowerShell Method (if you have admin access):**")
print(" Connect-PnPOnline -Url https://tenant-admin.sharepoint.com -Interactive")
print(f" Register-PnPAzureADApp -ApplicationName 'SharePoint-FileCloud-Sync' -Tenant {tenant}.onmicrosoft.com -Interactive")
print()
Return Value
Returns None implicitly. The function's primary purpose is to print formatted troubleshooting instructions to the console. It may return early (None) if configuration cannot be loaded or if the tenant cannot be extracted from the SharePoint URL.
Dependencies
requestsjson
Required Imports
import requests
import json
Usage Example
# Assuming load_config() function is defined and returns a dict with required keys
# Example configuration:
# config = {
# 'SHAREPOINT_SITE_URL': 'https://contoso.sharepoint.com/sites/mysite',
# 'AZURE_CLIENT_ID': '12345678-1234-1234-1234-123456789abc'
# }
test_tenant_admin_center_approach()
# Output will display:
# - Tenant admin center URL
# - Step-by-step instructions for three different configuration methods
# - Specific URLs and commands customized for the tenant
Best Practices
- Ensure load_config() function is properly implemented and returns a dictionary with required keys before calling this function
- This function requires SharePoint admin privileges to execute the suggested solutions
- The function assumes the SharePoint URL follows the standard format: https://{tenant}.sharepoint.com
- This is a diagnostic/helper function meant for interactive use, not for automated workflows
- The function prints directly to console, so it's best used in CLI tools or debugging scenarios
- Consider wrapping this function in error handling if used in production environments
- The PowerShell commands shown require PnP PowerShell module to be installed
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function provide_admin_instructions 84.7% similar
-
function main_v27 75.6% similar
-
function main_v26 72.4% similar
-
function test_sharepoint_token 69.7% similar
-
function test_azure_token 67.6% similar