Difference between revisions of "Legacy Mojang Authentication"

From wiki.vg
Jump to navigation Jump to search
m
(Added some common errors)
Line 33: Line 33:
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
=== Errors ===
 +
These are some of the errors that can be encountered:
 +
{| class="wikitable"
 +
|-
 +
! Error
 +
! Cause
 +
! Error message
 +
! Notes
 +
|-
 +
| <code>Method Not Allowed</code>
 +
|
 +
| The method specified in the request is not allowed for the resource identified by the request URI
 +
| Something other than a POST request was received.
 +
|-
 +
| <code>Not Found</code>
 +
|
 +
| The server has not found anything matching the request URI
 +
| Non-existing endpoint was called.
 +
|-
 +
| <code>ForbiddenOperationException</code>
 +
| <code>UserMigratedException</code>
 +
| Invalid credentials. Account migrated, use e-mail as username.
 +
|
 +
|-
 +
| <code>ForbiddenOperationException</code>
 +
|
 +
| Invalid credentials. Invalid username or password.
 +
|
 +
|-
 +
| <code>ForbiddenOperationException</code>
 +
|
 +
| Invalid token.
 +
| <code>accessToken</code> was invalid.
 +
|-
 +
| <code>IllegalArgumentException</code>
 +
|
 +
| Access token already has a profile assigned.
 +
| Selecting profiles isn't implemented yet.
 +
|}
 +
  
 
=== Session ID ===
 
=== Session ID ===
Line 39: Line 81:
  
 
   token:<accessToken>:<profile ID>
 
   token:<accessToken>:<profile ID>
 +
  
 
=== Authenticate ===
 
=== Authenticate ===
Line 64: Line 107:
 
The <code>clientToken</code> should be a randomly generated identifier and must be identical for each request.
 
The <code>clientToken</code> should be a randomly generated identifier and must be identical for each request.
 
In case it is omitted the server will generate a random token based on Java's [http://docs.oracle.com/javase/7/docs/api/java/util/UUID.html#toString() UUID.toString()] which should then be stored by the client. This will however also invalidate all previously acquired <code>accessToken</code>s for this user across all clients.
 
In case it is omitted the server will generate a random token based on Java's [http://docs.oracle.com/javase/7/docs/api/java/util/UUID.html#toString() UUID.toString()] which should then be stored by the client. This will however also invalidate all previously acquired <code>accessToken</code>s for this user across all clients.
 
  
 
==== Response ====
 
==== Response ====
Line 86: Line 128:
  
 
Currently each account will only have one single profile, multiple profiles per account are however planned in the future.
 
Currently each account will only have one single profile, multiple profiles per account are however planned in the future.
 +
  
 
=== Refresh ===
 
=== Refresh ===
Line 100: Line 143:
 
   "clientToken": "client identifier"    // This needs to be identical to the one used
 
   "clientToken": "client identifier"    // This needs to be identical to the one used
 
                                         // to obtain the accessToken in the first place
 
                                         // to obtain the accessToken in the first place
 +
  "selectedProfile": {                  // optional; sending it will result in an error
 +
    "id": "profile identifier",          // hexadecimal
 +
    "name": "player name"
 +
  }
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 114: Line 161:
 
     "name": "player name"
 
     "name": "player name"
 
   }
 
   }
}
+
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
 
=== Validate ===
 
=== Validate ===

Revision as of 14:12, 16 July 2013

The minecraft client and server communicate with Mojang to validate player sessions. This page describes some of the operations.

Authentication

Minecraft 1.6 introduced a new authentication scheme called Yggdrasil which completely replaces the previous authentication system.

Request format

All requests to Yggdrasil are made to the following server:

 https://authserver.mojang.com

Further, they are expected to fulfill the following rules:

  • Are POST requests
  • Have the Content-Type header set to application/json
  • Contain a JSON-encoded dictionary as payload

If a request was successful the server will respond with:

  • Status code 200
  • A JSON-encoded dictionary according to the specifications below

If however a request fails, the server will respond with:

{
  "error": "Short description of the error",
  "errorMessage": "Longer description which can be shown to the user",
  "cause": "Cause of the error"        // optional
}


Errors

These are some of the errors that can be encountered:

Error Cause Error message Notes
Method Not Allowed The method specified in the request is not allowed for the resource identified by the request URI Something other than a POST request was received.
Not Found The server has not found anything matching the request URI Non-existing endpoint was called.
ForbiddenOperationException UserMigratedException Invalid credentials. Account migrated, use e-mail as username.
ForbiddenOperationException Invalid credentials. Invalid username or password.
ForbiddenOperationException Invalid token. accessToken was invalid.
IllegalArgumentException Access token already has a profile assigned. Selecting profiles isn't implemented yet.


Session ID

Whenever a Mojang service requires a session ID, you can simply combine a valid accessToken with a profile identifier as follows:

 token:<accessToken>:<profile ID>


Authenticate

Authenticates a user using his password.

Endpoint

 /authenticate

Payload

{
  "agent": {                             // optional
    "name": "Minecraft",                 // So far this is the only encountered value
    "version": 1                         // This number might be increased
                                         // by the vanilla client in the future
  },
  "username": "mojang account name",     // Can be an email address or player name for
                                         // unmigrated accounts
  "password": "mojang account password",
  "clientToken": "client identifier"     // optional
}

The clientToken should be a randomly generated identifier and must be identical for each request. In case it is omitted the server will generate a random token based on Java's UUID.toString() which should then be stored by the client. This will however also invalidate all previously acquired accessTokens for this user across all clients.

Response

{
  "accessToken": "random access token",  // hexadecimal
  "clientToken": "client identifier",    // identical to the one received
  "availableProfiles": [                 // only present if the agent field was received
    {
      "id": "profile identifier",        // hexadecimal
      "name": "player name"
    }
  ],
  "selectedProfile": {                   // only present if the agent field was received
    "id": "profile identifier",
    "name": "player name"
  }
}

Note: If a user wishes to stay logged in on his computer you are strongly advised to store the received accessToken instead of the password itself.

Currently each account will only have one single profile, multiple profiles per account are however planned in the future.


Refresh

Refreshes a valid accessToken. It can be uses to keep a user logged in between gaming sessions and is preferred over storing the user's password in a file (see lastlogin).

Endpoint

 /refresh

Payload

{
  "accessToken": "valid accessToken",
  "clientToken": "client identifier"     // This needs to be identical to the one used
                                         // to obtain the accessToken in the first place
  "selectedProfile": {                   // optional; sending it will result in an error
    "id": "profile identifier",          // hexadecimal
    "name": "player name"
  }
}

Note: The provided accessToken gets invalidated.

Response

{
  "accessToken": "random access token",  // hexadecimal
  "clientToken": "client identifier",    // identical to the one received
  "selectedProfile": {
    "id": "profile identifier",          // hexadecimal
    "name": "player name"
  }
}


Validate

Checks if an accessToken is valid.

Endpoint

 /validate

Payload

{
  "accessToken": "valid accessToken",
}

Response

Unlike most other methods this one will return an empty payload if successful.

Joining a Server

See Protocol Encryption for details on encrypting connections.

Client operation

  1. Client connects to server
  2. Client sends a 0x02 handshake containing the current player name
  3. Client receives an 0xFD encryption request with the server's public key and four verification bytes.
  4. Client generates a symmetric key.
  5. Client sends a HTTP request to
    http://session.minecraft.net/game/joinserver.jsp?user=<player name>&sessionId=<session id>&serverId=<server hash>
    Note: See the Session ID section on how the <session id> is generated.
    If the response is OK then continue, otherwise stop
  6. Client sends 0xFC encryption response - client encrypts shared secret and verification token with the server's public key
  7. Server checks validity and sends 0xFC encryption response with two empty arrays
  8. Both sides enable AES/CFB2 encryption using the shared secret generated by the client
  9. Client sends 0xCD client status with a payload of 0 (ready to spawn)
  10. Server sends 0x01 login
  11. ... receive map chunks, etc...

Server operation

  1. Server generates a 1024-bit RSA keypair.
  2. ...
  3. Server answers TCP connection request and receives a 0x02 handshake from the client.
  4. Server sends 0xFD encryption request with its public key and a verification token.
  5. Server receives 0xFC encryption response from client and decrypts the shared secret.
  6. Server verifies the validity of the verification token. If this isn't verified, it kicks the client.
  7. Server sends a HTTP request to
    http://session.minecraft.net/game/checkserver.jsp?user=<username>&serverId=<server hash>
    If it returns YES then the client is authenticated and allowed to join. Otherwise the client will/should be kicked with “Failed to verify username!”
  8. Server sends a 0xFC encryption response packet with two empty arrays.
  9. Both sides enable AES/CFB2 encryption.
  10. Server receives 0xCD client status with a payload of , indicating "ready to spawn"
  11. Server sends 0x01 login
  12. ... send map chunks, etc...