Apple Developer Account: Enterprise - error 'There was an error while trying to log in: Provide a properly configured and signed bearer token, and make sure that it has not expired learn more about generating tokens for API requests'

MORA MENESES RUBEN 0 Reputation points
2025-02-04T15:10:57.61+00:00

I achieved to connect the remote mac from the "Pair to mac" option in Visual studio 2022 from Windows, then when in tools/options/xamarin/apple accounts I tried to pair the apple enterprise account, I get an error saying "There was an error while trying to sign in: Please provide a properly signed and configured bearer token, and make sure it has not expired. Learn more about generating tokens for API requests"

User's image

I read and followed the documentation (https://learn.microsoft.com/en-us/dotnet/maui/ios/apple-account-management?view=net-maui-8.0), but the error still shows, I've seen many videos, none of them have the same issue, and this ticked didn't help me: https://learn.microsoft.com/en-us/answers/questions/1099423/apple-developer-account-individual-error-there-was.
Same problem than Brian Kekana, but Enterprise Account. My specifications:

User's image

XCode Mac is up to date also

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,447 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,962 questions
{count} votes

1 answer

Sort by: Most helpful
  1. jeet gaglani 5 Reputation points
    2025-02-05T07:18:50.45+00:00

    Hey MORA MENESES RUBEN,

    The error is due to an issue with the bearer token used to authenticate your Apple Enterprise account in Visual Studio 2022. Try following below mentioned steps:**

    Steps to resolve:

    1. Check Bearer Token Expiry:

    Apple’s API authentication tokens expire after a certain period. Generate a new one.

    1. Generate a New Bearer Token:

    Go to Apple Developer.

    Navigate to Keys under Certificates, Identifiers & Profiles.

    Create a new Auth Key if needed.

    Download and securely store the .p8 file.

    1. Configure Visual Studio Properly:

    In Tools → Options → Xamarin → Apple Accounts, remove and re-add your account.

    Use the new bearer token.

    1. Ensure Xcode and macOS Are Updated:

    Since you are pairing with a Mac, ensure Xcode is fully updated.

    Restart both Windows and macOS.

    1. Check Your Team ID & Key ID:

    The Auth Key requires a Key ID and Team ID to work.

    Verify that they are correctly entered in Visual Studio.

    1. Firewall and Network Check:

    Make sure no firewall or VPN is blocking authentication requests to Apple.

    If the issue persists, try using Apple ID authentication instead of an API key to sign in.

    1. Generate a JWT Bearer Token

    ---Python Script for Generating Apple Bearer Token---

    import jwt # Install with pip install pyjwt

    import time

    Required Details (Replace these with your actual details)

    KEY_ID = "YOUR_KEY_ID" # Found in Apple Developer → Keys section

    TEAM_ID = "YOUR_TEAM_ID" # Your Apple Developer Team ID

    PRIVATE_KEY_PATH = "AuthKey_YOUR_KEY_ID.p8" # Path to your private key file

    ISSUER = TEAM_ID # The Team ID is also used as Issuer

    Generate JWT Token

    def generate_apple_jwt():
    
    with open(PRIVATE_KEY_PATH, "r") as key_file:
    
        private_key = key_file.read()
    
    payload = {
    
        "iss": ISSUER,
    
        "iat": int(time.time()),
    
        "exp": int(time.time()) + 3600,  # Token valid for 1 hour
    
        "aud": "appstoreconnect-v1"
    
    }
    
    headers = {
    
        "alg": "ES256",
    
        "kid": KEY_ID
    
    }
    
    token = jwt.encode(payload, private_key, algorithm="ES256", headers=headers)
    
    return token
    # Generate and print the token
    
    bearer_token = generate_apple_jwt()
    
    print("Generated Bearer Token:", bearer_token)
    
    1. Use the Token in Visual Studio

    After running the script, you’ll get a bearer token. Use it in Visual Studio:

    • Open Visual Studio.
    • Go to Tools → Options → Xamarin → Apple Accounts.
    • Click Add Apple Account.
    • Select Use API Key instead of Apple ID.
    • Enter:
      • Issuer ID (Your Team ID)
      • Key ID (Found in Apple Developer Portal under Keys)
      • Generated Bearer Token
    • Click OK and try signing in again.
    1. Debugging Issues

    If you still get an error:

    • Ensure your private key (.p8) file is correctly referenced.
    • Make sure the token is not expired (iat and exp values in the script).
    • Double-check that the Key ID and Team ID are correct.
    • Ensure your account has Admin or Developer permissions on the Apple Developer portal.

    please review my answer and let me know if need any further help.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.