šŸ” Code Extractor

function provide_admin_instructions

Maturity: 42

Displays comprehensive administrative instructions for fixing SharePoint app-only authentication issues by loading configuration and presenting multiple resolution options.

File:
/tf/active/vicechatdev/SPFCsync/check_tenant_config.py
Lines:
173 - 217
Complexity:
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

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function test_tenant_admin_center_approach 84.7% similar

    Displays detailed troubleshooting instructions for resolving SharePoint 'Unsupported app only token' errors by providing three alternative configuration approaches through tenant admin center.

    From: /tf/active/vicechatdev/SPFCsync/diagnose_permissions.py
  • function main_v20 75.2% similar

    Interactive CLI helper function that generates and displays instructions for granting SharePoint app permissions to an Azure AD application.

    From: /tf/active/vicechatdev/SPFCsync/grant_sharepoint_access.py
  • function main_v27 72.5% similar

    Entry point function that runs a SharePoint permission diagnostic tool, testing different authentication scopes and providing troubleshooting guidance.

    From: /tf/active/vicechatdev/SPFCsync/diagnose_permissions.py
  • function main_v26 67.6% similar

    Diagnostic function that tests SharePoint tenant configuration by checking Microsoft Graph API access and provides recommendations based on the results.

    From: /tf/active/vicechatdev/SPFCsync/check_tenant_config.py
  • function main_v22 62.5% similar

    Orchestrates a comprehensive SharePoint connection diagnostic tool that validates Azure AD authentication and SharePoint access by running multiple tests and reporting results.

    From: /tf/active/vicechatdev/SPFCsync/diagnose_sharepoint.py
← Back to Browse