Interface AltLoginService


public interface AltLoginService
Contract for Minecraft account authentication services. Provides asynchronous methods to log into accounts via Microsoft OAuth, browser cookies, session tokens, refresh tokens, or offline (cracked) identities.

No route throws at the caller or completes its future exceptionally. Every failure, a runtime closed before the route started included, is a LoginResult whose LoginResult.failure() says what kind it was (AltsFailure.Kind.CANCELLED for a closed runtime or a refusing executor).

Not designed for host implementation; methods may be added in minor releases.

Since:
0.1.0
  • Method Details

    • loginMicrosoft

      CompletableFuture<LoginResult> loginMicrosoft(LoginMode mode)
      Initiates authentication through the official Microsoft OAuth2 flow.
      Parameters:
      mode - the login mode (whether to add the account to storage)
      Returns:
      a future containing the result of the login attempt
      Since:
      0.1.0
    • loginDeviceCode

      default CompletableFuture<LoginResult> loginDeviceCode(DeviceCodePrompt prompt, LoginMode mode)
      Initiates authentication through the OAuth device-authorization grant: the host shows the user a short code and an address through prompt, the user enters the code in any browser on any device, and the library polls until the sign-in is approved, declined, or expires. It needs no loopback port and no local browser, so it is the interactive route for a headless or locked-down machine. The resulting account carries a refresh token exactly as loginMicrosoft(LoginMode) does.

      The library never opens a browser for this flow and never prints the code. Cancelling the returned future stops the polling.

      Phishing. A device code signs in whoever started the flow, not whoever types the code. Call this only on an explicit action by the user, and always display the real verification address the prompt is given.

      The default implementation reports NOT_CONFIGURED: a login service that offers no device-code sign-in says so as a result, like every other failure, rather than by throwing.

      Parameters:
      prompt - the host seam that shows the user the code and the verification address
      mode - the login mode (whether to add the account to storage)
      Returns:
      a future containing the result of the login attempt
      Since:
      0.12.0
    • loginCookie

      CompletableFuture<LoginResult> loginCookie(String cookieData, LoginMode mode)
      Authenticates using raw browser cookie data. Reuses an existing browser session: the cookies, exported from a browser already signed in, sign the account in without asking for its password again.
      Parameters:
      cookieData - the cookie string in Netscape or mangled format
      mode - the login mode
      Returns:
      a future containing the result of the login attempt
      Since:
      0.1.0
    • loginCookieFile

      CompletableFuture<LoginResult> loginCookieFile(Path file, LoginMode mode)
      Authenticates using cookies exported to a file, which is the shape browser extensions produce them in. The file is read off the calling thread; decoding and parsing are handled for the caller, so a host only has to supply a path.
      Parameters:
      file - the exported cookie file, in Netscape or mangled format
      mode - the login mode
      Returns:
      a future containing the result of the login attempt
      Since:
      0.7.0
    • loginSession

      CompletableFuture<LoginResult> loginSession(String sessionToken, LoginMode mode)
      Authenticates using a pre-existing Minecraft access token or session string.
      Parameters:
      sessionToken - the raw access token or session string
      mode - the login mode
      Returns:
      a future containing the result of the login attempt
      Since:
      0.1.0
    • loginRefreshToken

      CompletableFuture<LoginResult> loginRefreshToken(String refreshToken, LoginMode mode)
      Authenticates using a stored OAuth refresh token, skipping the interactive browser step. The token endpoint issues a rotated refresh token, which is stored on the resulting account.
      Parameters:
      refreshToken - the OAuth refresh token to redeem
      mode - the login mode
      Returns:
      a future containing the result of the login attempt
      Since:
      0.6.0
    • loginOffline

      CompletableFuture<LoginResult> loginOffline(String username, LoginMode mode)
      Authenticates for offline (cracked) play using only a username.
      Parameters:
      username - the desired offline username
      mode - the login mode
      Returns:
      a future containing the result of the login attempt
      Since:
      0.1.0
    • loginAccount

      CompletableFuture<LoginResult> loginAccount(AltAccount account)
      Performs a login operation using an existing AltAccount data model.
      Parameters:
      account - the account data to authenticate with
      Returns:
      a future containing the result of the login attempt
      Since:
      0.1.0
    • routed

      AltLoginService routed(String tag)
      Returns a view of this login service whose every request carries tag as the route tag its proxy provider sees, on every hop of every route: the token exchange, Xbox Live, XSTS, the Minecraft services login, the profile lookup, the cookie chain, and the renewal behind loginAccount(AltAccount). For a host that pins each account to its own proxy and has to route a new account's first sign-in before any account UUID exists to route on. The view stores, injects and classifies exactly as this service does; only the tag differs.

      The tag belongs to the sign-in, not to the account it produces. Once the account exists, what is done with it is routed by its UUID like any other: AltsRuntime#accountServices, a bulk check or refresh, and a later loginAccount through the service itself carry no tag. A host that wants the account kept on the same proxy maps its UUID to that proxy in its provider.

      Parameters:
      tag - the host's route tag
      Returns:
      the tagged view
      Throws:
      NullPointerException - if tag is null
      IllegalArgumentException - if tag is blank
      Since:
      1.0.0