function provide_admin_instructions
Displays comprehensive administrative instructions for fixing SharePoint app-only authentication issues by loading configuration and presenting multiple resolution options.
/tf/active/vicechatdev/SPFCsync/check_tenant_config.py
173 - 217
simple
Purpose
This function provides step-by-step troubleshooting instructions for SharePoint administrators to enable app-only authentication. It extracts tenant and client ID information from configuration and presents four different approaches: SharePoint Admin Center settings, API Management approval, PowerShell commands, and IT admin contact template. The function is designed to guide users through resolving authentication/permission issues when connecting to SharePoint.
Source Code
def provide_admin_instructions():
"""Provide detailed admin instructions."""
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:
return
print("\n" + "=" * 60)
print("š ADMIN INSTRUCTIONS TO FIX THE ISSUE")
print("=" * 60)
print("\nš§ **Option 1: Enable via SharePoint Admin Center**")
print(f"1. Go to: https://{tenant}-admin.sharepoint.com")
print("2. Navigate to: Settings ā Classic settings page")
print("3. Scroll to 'Apps' section")
print("4. Check: 'Allow apps that don't require custom code'")
print("5. Save changes")
print("\nš§ **Option 2: API Management**")
print(f"1. Go to: https://{tenant}-admin.sharepoint.com")
print("2. Navigate to: Advanced ā API Management")
print("3. Click: 'Approve or reject pending requests'")
print("4. Look for pending requests and approve them")
print("\nš§ **Option 3: PowerShell (if PnP module installed)**")
print("1. Install PnP PowerShell:")
print(" Install-Module -Name PnP.PowerShell -Force")
print("2. Connect and enable:")
print(f" Connect-PnPOnline -Url https://{tenant}-admin.sharepoint.com -Interactive")
print(" Set-PnPTenant -DisableAppOnlyPermissionUsage $false")
print(f" Grant-PnPAzureADAppSitePermission -AppId {client_id} -DisplayName 'SP-Sync' -Permissions Read")
print("\nš§ **Option 4: Contact IT Admin**")
print("If you don't have admin access, send this to your IT admin:")
print(f"- Tenant: {tenant}")
print(f"- App ID: {client_id}")
print("- Request: Enable app-only authentication for SharePoint")
print("- Purpose: Document synchronization to FileCloud")
Return Value
Returns None implicitly. The function performs side effects by printing formatted instructions to stdout. If configuration cannot be loaded or the site URL doesn't contain '.sharepoint.com', the function returns early without output.
Usage Example
# Assuming load_config() 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'
# }
provide_admin_instructions()
# Output will display formatted instructions with:
# - Tenant name extracted from URL (e.g., 'contoso')
# - Four different options for fixing authentication issues
# - Specific commands and URLs customized to the tenant
# - Client ID for admin reference
Best Practices
- Ensure load_config() function is properly implemented and returns a dictionary with required keys before calling this function
- This function should be called when SharePoint authentication fails due to app-only permission issues
- The function performs early returns if configuration is missing or invalid - ensure proper error handling in calling code
- Consider capturing the output if you need to log or display instructions in a different format (currently prints directly to stdout)
- The SharePoint site URL must be a valid SharePoint Online URL containing '.sharepoint.com' for tenant extraction to work
- This is a display-only function with no side effects beyond console output - safe to call multiple times
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function test_tenant_admin_center_approach 84.7% similar
-
function main_v34 75.7% similar
-
function main_v47 73.3% similar
-
function main_v44 67.6% similar
-
function main_v43 63.0% similar