Class MicrosoftAuthConfig

java.lang.Object
lol.trq.alts.auth.MicrosoftAuthConfig

public final class MicrosoftAuthConfig extends Object
Microsoft / Xbox Live authentication configuration the host supplies. The clientId is the host's own Azure application id and is required — the library ships no default, so an implementer must register their own app rather than sharing one. The scope, the local redirect path, and every service endpoint default to the public Microsoft / Xbox / Minecraft URLs and are only overridden when an implementer fronts them with a proxy or targets a non-standard deployment.

Build the common case with of(String) and adjust with the withX copy methods. A legacy MSA application is a different protocol dialect and comes from legacyMsa(String). A blank optional value always falls back to its default.

A final class rather than a record since 1.0.0, so a later setting is an addition and not a break. Two configs are equal when every value is.

Since:
0.2.0
  • Field Details

    • DEFAULT_SCOPE

      public static final String DEFAULT_SCOPE
      Default OAuth scope for a Minecraft login.
      Since:
      0.2.0
      See Also:
    • DEFAULT_REDIRECT_PATH

      public static final String DEFAULT_REDIRECT_PATH
      Default loopback callback path — intentionally long to reduce accidental screen-share exposure. The browser sign-in redirects to http://localhost:<port> followed by this path, so the host's app registration lists it. Changed in 1.0.0: a registration that lists the 0.12 default keeps working by passing that path to withRedirectPath(String).
      Since:
      0.2.0
      See Also:
    • DEFAULT_AUTHORIZE_URL

      public static final String DEFAULT_AUTHORIZE_URL
      Default OAuth authorize endpoint.
      Since:
      0.2.0
      See Also:
    • DEFAULT_TOKEN_URL

      public static final String DEFAULT_TOKEN_URL
      Default OAuth token endpoint.
      Since:
      0.2.0
      See Also:
    • DEFAULT_XBOX_LIVE_AUTH_URL

      public static final String DEFAULT_XBOX_LIVE_AUTH_URL
      Default Xbox Live user-authentication endpoint.
      Since:
      0.2.0
      See Also:
    • DEFAULT_XSTS_AUTH_URL

      public static final String DEFAULT_XSTS_AUTH_URL
      Default XSTS authorization endpoint.
      Since:
      0.2.0
      See Also:
    • DEFAULT_MINECRAFT_LOGIN_URL

      public static final String DEFAULT_MINECRAFT_LOGIN_URL
      Default Minecraft services login-with-Xbox endpoint.
      Since:
      0.2.0
      See Also:
    • DEFAULT_MINECRAFT_PROFILE_URL

      public static final String DEFAULT_MINECRAFT_PROFILE_URL
      Default Minecraft services profile endpoint.
      Since:
      0.2.0
      See Also:
    • DEFAULT_RPS_TICKET_PREFIX

      public static final String DEFAULT_RPS_TICKET_PREFIX
      Prefix marking an OAuth 2.0 access token as delegated when it is exchanged at Xbox Live.
      Since:
      0.7.0
      See Also:
    • LEGACY_MSA_SCOPE

      public static final String LEGACY_MSA_SCOPE
      The scope a legacy MSA application authenticates Xbox Live with.
      Since:
      0.7.0
      See Also:
    • LEGACY_MSA_REDIRECT_URI

      public static final String LEGACY_MSA_REDIRECT_URI
      The redirect a legacy MSA application's token grant must declare.
      Since:
      0.7.0
      See Also:
    • LEGACY_MSA_RPS_TICKET_PREFIX

      public static final String LEGACY_MSA_RPS_TICKET_PREFIX
      Prefix marking a legacy MSA access token as an RPS ticket proper.
      Since:
      0.7.0
      See Also:
    • DEFAULT_DEVICE_CODE_URL

      public static final String DEFAULT_DEVICE_CODE_URL
      Default device-authorization endpoint, on the consumers tenant of the Microsoft identity platform.
      Since:
      0.12.0
      See Also:
    • DEFAULT_DEVICE_TOKEN_URL

      public static final String DEFAULT_DEVICE_TOKEN_URL
      Default token endpoint the device-code login polls. It is a different endpoint from DEFAULT_TOKEN_URL: a device code is redeemed where it was issued.
      Since:
      0.12.0
      See Also:
  • Method Details

    • of

      public static MicrosoftAuthConfig of(String clientId)
      Creates a config for the given client id with every other value defaulted.
      Parameters:
      clientId - the host's Azure application client id; required
      Returns:
      a fully-defaulted config
      Since:
      0.2.0
    • legacyMsa

      public static MicrosoftAuthConfig legacyMsa(String clientId)
      Creates a config for a legacy MSA application — the pre-Azure registration shape.

      Three things differ from an OAuth app and all three are load-bearing: the token grant must declare LEGACY_MSA_REDIRECT_URI, it must ask for LEGACY_MSA_SCOPE instead of the delegated Xbox scopes, and the access token it returns is an RPS ticket that Xbox Live wants prefixed t= rather than d=. Sending the OAuth shape to one of these apps is answered with a flat 400.

      Refresh tokens are the practical use: the interactive browser flow needs the desktop redirect these apps declare, which the loopback callback server cannot serve.

      Parameters:
      clientId - the legacy application id; required
      Returns:
      a config speaking the legacy MSA dialect
      Since:
      0.7.0
    • withClientId

      public MicrosoftAuthConfig withClientId(String value)
      Returns a copy targeting a different application, keeping the dialect and endpoints.
      Parameters:
      value - the new client id; required
      Returns:
      a copy with the client id replaced
      Since:
      0.7.0
    • withScope

      public MicrosoftAuthConfig withScope(String value)
      Returns a copy with the OAuth scope replaced.
      Parameters:
      value - the new scope, or null/blank to keep the default
      Returns:
      a copy with the scope replaced
      Since:
      0.2.0
    • withRedirectPath

      public MicrosoftAuthConfig withRedirectPath(String value)
      Returns a copy with the local redirect path replaced.
      Parameters:
      value - the new redirect path, or null/blank to keep the default
      Returns:
      a copy with the redirect path replaced
      Since:
      0.2.0
    • withEndpoints

      public MicrosoftAuthConfig withEndpoints(String authorizeUrl, String tokenUrl, String xboxLiveAuthUrl, String xstsAuthUrl, String minecraftLoginUrl, String minecraftProfileUrl)
      Returns a copy with all six service endpoints replaced (each null/blank argument keeps its default). For implementers fronting Microsoft / Xbox / Minecraft services with their own proxy.
      Parameters:
      authorizeUrl - the OAuth authorize endpoint
      tokenUrl - the OAuth token endpoint
      xboxLiveAuthUrl - the Xbox Live user-authentication endpoint
      xstsAuthUrl - the XSTS authorization endpoint
      minecraftLoginUrl - the Minecraft services login-with-Xbox endpoint
      minecraftProfileUrl - the Minecraft services profile endpoint
      Returns:
      a copy with the endpoints replaced
      Since:
      0.2.0
    • withDeviceCodeEndpoints

      public MicrosoftAuthConfig withDeviceCodeEndpoints(String deviceCodeUrl, String deviceTokenUrl)
      Returns a copy with the two device-code endpoints replaced (each null/blank argument keeps its default). Kept apart from withEndpoints(String, String, String, String, String, String) so that method's signature is unchanged.
      Parameters:
      deviceCodeUrl - the device-authorization endpoint
      deviceTokenUrl - the token endpoint the device-code login polls
      Returns:
      a copy with the device-code endpoints replaced
      Since:
      0.12.0
    • clientId

      public String clientId()
      Returns the host's Azure application (OAuth) client id.
      Returns:
      the client id
      Since:
      0.2.0
    • scope

      public String scope()
      Returns the OAuth scope to request.
      Returns:
      the value, defaulted when none was given
      Since:
      0.2.0
    • redirectPath

      public String redirectPath()
      Returns the local callback path the loopback redirect server listens on.
      Returns:
      the value, defaulted when none was given
      Since:
      0.2.0
    • authorizeUrl

      public String authorizeUrl()
      Returns the OAuth authorize endpoint.
      Returns:
      the value, defaulted when none was given
      Since:
      0.2.0
    • tokenUrl

      public String tokenUrl()
      Returns the OAuth token endpoint.
      Returns:
      the value, defaulted when none was given
      Since:
      0.2.0
    • xboxLiveAuthUrl

      public String xboxLiveAuthUrl()
      Returns the Xbox Live user-authentication endpoint.
      Returns:
      the value, defaulted when none was given
      Since:
      0.2.0
    • xstsAuthUrl

      public String xstsAuthUrl()
      Returns the XSTS authorization endpoint.
      Returns:
      the value, defaulted when none was given
      Since:
      0.2.0
    • minecraftLoginUrl

      public String minecraftLoginUrl()
      Returns the Minecraft services login-with-Xbox endpoint.
      Returns:
      the value, defaulted when none was given
      Since:
      0.2.0
    • minecraftProfileUrl

      public String minecraftProfileUrl()
      Returns the Minecraft services profile endpoint.
      Returns:
      the value, defaulted when none was given
      Since:
      0.2.0
    • redirectUri

      public String redirectUri()
      Returns the redirect_uri the refresh grant must carry; the authorization-code grant ignores this and uses the address the callback server actually served.
      Returns:
      the redirect URI, or null to omit it
      Since:
      0.7.0
    • rpsTicketPrefix

      public String rpsTicketPrefix()
      Returns the prefix the Microsoft access token carries into the Xbox Live RPS ticket.
      Returns:
      the value, defaulted when none was given
      Since:
      0.7.0
    • deviceCodeUrl

      public String deviceCodeUrl()
      Returns the device-authorization endpoint the device-code login starts at.
      Returns:
      the value, defaulted when none was given
      Since:
      0.12.0
    • deviceTokenUrl

      public String deviceTokenUrl()
      Returns the token endpoint the device-code login polls.
      Returns:
      the value, defaulted when none was given
      Since:
      0.12.0
    • withRedirectUri

      public MicrosoftAuthConfig withRedirectUri(String value)
      Returns a copy with the redirect_uri the refresh grant carries replaced. An OAuth app's refresh grant carries none; a legacy MSA app's declares LEGACY_MSA_REDIRECT_URI.
      Parameters:
      value - the redirect URI, or null/blank to omit it
      Returns:
      a copy with the redirect URI replaced
      Since:
      1.0.0
    • withRpsTicketPrefix

      public MicrosoftAuthConfig withRpsTicketPrefix(String value)
      Returns a copy with the RPS ticket prefix replaced.
      Parameters:
      value - the prefix, or null/blank to keep the default (DEFAULT_RPS_TICKET_PREFIX)
      Returns:
      a copy with the prefix replaced
      Since:
      1.0.0
    • equals

      public boolean equals(Object o)
      Returns whether o is a config with every value equal to this one's.
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare
      Returns:
      true when every value is equal
      Since:
      0.2.0
    • hashCode

      public int hashCode()
      Returns a hash over every value, consistent with equals(Object).
      Overrides:
      hashCode in class Object
      Returns:
      the hash
      Since:
      0.2.0
    • toString

      public String toString()
      Returns every value, in the form the record printed them. The config holds no secret.
      Overrides:
      toString in class Object
      Returns:
      a description
      Since:
      0.2.0