{"library":"pyobjc-framework-authenticationservices","title":"PyObjC AuthenticationServices Framework","description":"PyObjC is a bridge between Python and Objective-C, enabling Python developers to write full-featured macOS Cocoa applications. The `pyobjc-framework-authenticationservices` package provides Python wrappers for the macOS `AuthenticationServices` framework. It is currently at version 12.1 and follows the release cadence of the broader PyObjC project, typically releasing new versions to align with macOS SDK updates and Python version support changes.","language":"python","status":"active","last_verified":"Sat May 16","install":{"commands":["pip install pyobjc-framework-authenticationservices"],"cli":null},"imports":["import AuthenticationServices","from AuthenticationServices import ASWebAuthenticationSession","from AppKit import NSApplication"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import objc\nfrom AppKit import NSApplication, NSApp, NSWindow, NSApplicationActivationPolicyRegular\nfrom Foundation import NSObject, NSURL, NSError\nfrom AuthenticationServices import (\n    ASWebAuthenticationSession,\n    ASWebAuthenticationSessionDelegate,\n    ASWebAuthenticationPresentationContextProviding,\n)\nimport os\n\n# Define a delegate for ASWebAuthenticationSession and its presentation context\nclass WebAuthSessionDelegate(\n    NSObject,\n    ASWebAuthenticationSessionDelegate,\n    ASWebAuthenticationPresentationContextProviding,\n):\n    def init(self):\n        self = objc.super(WebAuthSessionDelegate, self).init()\n        return self\n\n    # Required ASWebAuthenticationSessionDelegate methods\n    def authenticationSession_didCompleteWithCallbackURL_(self, session, callbackURL):\n        print(f\"Authentication session completed with URL: {callbackURL.absoluteString()}\")\n        NSApp.terminate_(None)\n\n    def authenticationSession_didFailWithError_(self, session, error):\n        print(f\"Authentication session failed with error: {error.localizedDescription()}\")\n        NSApp.terminate_(None)\n\n    def authenticationSession_didCancel_(self, session):\n        print(\"Authentication session cancelled.\")\n        NSApp.terminate_(None)\n\n    # Required ASWebAuthenticationPresentationContextProviding method\n    def presentationAnchorForWebAuthenticationSession_(self, session):\n        # In a real GUI app, this would return the main window of your application.\n        # For a minimal example, we'll try to get the key window or create a dummy one.\n        # Note: The application needs to be activated for a window to be meaningfully presented.\n        if NSApp.keyWindow():\n            return NSApp.keyWindow()\n        else:\n            # Fallback for headless environments or early stages; may not always work perfectly\n            # Create a minimal, temporary window if no key window is available.\n            # This might not be suitable for all presentation contexts.\n            window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(((0,0),(1,1)), 0, 0, False)\n            window.makeKeyAndOrderFront_(None)\n            return window\n\ndef main():\n    # Establish a shared NSApplication instance\n    if not NSApp:\n        _ = NSApplication.sharedApplication()\n    NSApp.setActivationPolicy_(NSApplicationActivationPolicyRegular)\n\n    delegate_instance = WebAuthSessionDelegate.alloc().init()\n\n    # Dummy URLs for demonstration purposes\n    auth_url = NSURL.URLWithString_(\"https://www.example.com/auth\")\n    callback_scheme = \"myapp\" # e.g., 'myapp://callback'\n\n    # Create the authentication session\n    session = ASWebAuthenticationSession.alloc().initWithURL_callbackURLScheme_completionHandler_(\n        auth_url,\n        callback_scheme,\n        None # We use the delegate methods for completion/failure\n    )\n\n    # Set the delegate for both completion and presentation context\n    session.setDelegate_(delegate_instance)\n    session.setPresentationContextProvider_(delegate_instance)\n\n    # Start the session\n    print(\"Starting ASWebAuthenticationSession...\")\n    if not session.start():\n        print(\"Failed to start ASWebAuthenticationSession.\")\n        NSApp.terminate_(None)\n\n    # Run the application event loop until terminated by the delegate\n    NSApp.run()\n\nif __name__ == \"__main__\":\n    main()","lang":"python","description":"This quickstart demonstrates how to initiate a web authentication session using `ASWebAuthenticationSession` from the `AuthenticationServices` framework. It sets up a minimal `NSApplication` and defines a delegate to handle the authentication session's completion, failure, or cancellation, which are crucial for interactive macOS frameworks. The `presentationAnchorForWebAuthenticationSession_` method provides the necessary display context for the authentication UI.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":null,"pypi_latest":"12.1","is_stale":null,"summary":{"python_range":"3.10–3.9","success_rate":0,"avg_install_s":null,"avg_import_s":null,"wheel_type":null},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pyobjc-framework-authenticationservices","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pyobjc-framework-authenticationservices","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":3,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pyobjc-framework-authenticationservices","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pyobjc-framework-authenticationservices","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":3,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pyobjc-framework-authenticationservices","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pyobjc-framework-authenticationservices","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":2.9,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pyobjc-framework-authenticationservices","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pyobjc-framework-authenticationservices","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":2.5,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pyobjc-framework-authenticationservices","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pyobjc-framework-authenticationservices","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":3.5,"import_time_s":null,"mem_mb":null,"disk_size":null}]}}