# Generated from soulfire/mc-auth.proto. DO NOT EDIT.
# Generated by protoc-gen-connectrpc-py v0.13.0 with parameter "protobuf=google".
# ruff: noqa: PGH004
# ruff: noqa
# pyright: reportDeprecated=false
# ty: ignore[unused-ignore-comment]
# ty: ignore[deprecated, unused-ignore-comment]
# fmt: off
from __future__ import annotations
from typing import Protocol, TYPE_CHECKING
from connectrpc.client import ConnectClient, ConnectClientSync
from connectrpc.code import Code
from connectrpc.compat import google_protobuf_binary_codec, google_protobuf_codecs
from connectrpc.compression.gzip import GzipCompression
from connectrpc.errors import ConnectError
from connectrpc.method import IdempotencyLevel, MethodInfo, StreamType
from connectrpc.protocol import ProtocolType
from connectrpc.server import ConnectASGIApplication, ConnectWSGIApplication, DEFAULT_READ_MAX_BYTES, Endpoint, EndpointSync
from pyqwest import Client, SyncClient
from .mc_auth_pb2 import CredentialsAuthRequest, CredentialsAuthResponse, DeviceCodeAuthRequest, DeviceCodeAuthResponse, RefreshRequest, RefreshResponse
if TYPE_CHECKING:
from collections.abc import AsyncGenerator, AsyncIterator, Iterable, Iterator, Mapping
from connectrpc.codec import Codec
from connectrpc.compression import Compression
from connectrpc.interceptor import Interceptor, InterceptorSync
from connectrpc.request import Headers, RequestContext
_DEFAULT_CODECS = google_protobuf_codecs()
_PROTO_BINARY_CODEC = google_protobuf_binary_codec()
_GZIP_COMPRESSION = GzipCompression()
[docs]
class MCAuthService(Protocol):
"""
Service for authenticating Minecraft accounts for use with SoulFire bots.
Supports multiple authentication methods including Microsoft OAuth (credentials
and device code flows) and offline mode. All methods require the caller to
have AUTHENTICATE_MC_ACCOUNT permission for the target instance.
Authentication may optionally use proxies if configured in instance settings
(USE_PROXIES_FOR_ACCOUNT_AUTH). All authentication operations have timeouts
to prevent indefinite hangs (2 minutes for credentials/refresh, 15 minutes
for device code flow).
"""
[docs]
def login_credentials(self, request: CredentialsAuthRequest, ctx: RequestContext[CredentialsAuthRequest, CredentialsAuthResponse], /) -> AsyncIterator[CredentialsAuthResponse]:
"""
Authenticates one or more Minecraft accounts using credentials or tokens.
Supports bulk authentication with concurrent processing.
Results are streamed back as each authentication completes:
1. For each account, either a one_success (with account data) or
one_failure message is sent
2. A CredentialsAuthEnd message is sent when all checks are complete
Concurrency is controlled by the instance's ACCOUNT_IMPORT_CONCURRENCY setting.
Errors:
- NOT_FOUND: The specified instance does not exist
- PERMISSION_DENIED: Caller lacks AUTHENTICATE_MC_ACCOUNT permission
- INTERNAL: Authentication error (logged server-side with details)
Timeout: 2 minutes per account
"""
raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs]
def login_device_code(self, request: DeviceCodeAuthRequest, ctx: RequestContext[DeviceCodeAuthRequest, DeviceCodeAuthResponse], /) -> AsyncIterator[DeviceCodeAuthResponse]:
"""
Authenticates a Minecraft account using the Microsoft OAuth device code flow.
This is an interactive flow that requires user action in a web browser.
The stream first sends a DeviceCode message containing the verification
URL and user code. The client should display this to the user. Once the
user completes authorization in their browser, the stream sends the
authenticated account and completes.
Errors:
- NOT_FOUND: The specified instance does not exist
- PERMISSION_DENIED: Caller lacks AUTHENTICATE_MC_ACCOUNT permission
- INTERNAL: Authentication error (e.g., user denied access, timeout)
Timeout: 15 minutes (Microsoft device codes typically expire after this)
"""
raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs]
async def refresh(self, request: RefreshRequest, ctx: RequestContext[RefreshRequest, RefreshResponse], /) -> RefreshResponse:
"""
Refreshes the authentication tokens for an existing Minecraft account.
Used to renew expired access tokens using stored refresh tokens.
For Microsoft accounts, this refreshes the Minecraft token, profile,
and player certificates. For offline accounts, returns the account
unchanged (offline accounts never expire).
Errors:
- NOT_FOUND: The specified instance does not exist
- PERMISSION_DENIED: Caller lacks AUTHENTICATE_MC_ACCOUNT permission
- INTERNAL: Refresh error (e.g., refresh token expired or revoked)
Timeout: 2 minutes
"""
raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs]
class MCAuthServiceASGIApplication(ConnectASGIApplication[MCAuthService]):
def __init__(
self,
service: MCAuthService | AsyncGenerator[MCAuthService],
*,
interceptors: Iterable[Interceptor] = (),
read_max_bytes: int | None = DEFAULT_READ_MAX_BYTES,
compressions: Iterable[Compression] | None = None,
codecs: Iterable[Codec] | None = _DEFAULT_CODECS,
) -> None:
super().__init__(
service=service,
endpoints=lambda svc: {
"/soulfire.v1.MCAuthService/LoginCredentials": Endpoint.server_stream(
method=MethodInfo(
name="LoginCredentials",
service_name="soulfire.v1.MCAuthService",
input=CredentialsAuthRequest,
output=CredentialsAuthResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.SERVER_STREAM,
),
function=svc.login_credentials,
),
"/soulfire.v1.MCAuthService/LoginDeviceCode": Endpoint.server_stream(
method=MethodInfo(
name="LoginDeviceCode",
service_name="soulfire.v1.MCAuthService",
input=DeviceCodeAuthRequest,
output=DeviceCodeAuthResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.SERVER_STREAM,
),
function=svc.login_device_code,
),
"/soulfire.v1.MCAuthService/Refresh": Endpoint.unary(
method=MethodInfo(
name="Refresh",
service_name="soulfire.v1.MCAuthService",
input=RefreshRequest,
output=RefreshResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.UNARY,
),
function=svc.refresh,
),
},
interceptors=interceptors,
read_max_bytes=read_max_bytes,
compressions=compressions,
codecs=codecs,
)
@property
def path(self) -> str:
"""Returns the URL path to mount the application to when serving multiple applications."""
return "/soulfire.v1.MCAuthService"
[docs]
class MCAuthServiceClient(ConnectClient):
"""
Service for authenticating Minecraft accounts for use with SoulFire bots.
Supports multiple authentication methods including Microsoft OAuth (credentials
and device code flows) and offline mode. All methods require the caller to
have AUTHENTICATE_MC_ACCOUNT permission for the target instance.
Authentication may optionally use proxies if configured in instance settings
(USE_PROXIES_FOR_ACCOUNT_AUTH). All authentication operations have timeouts
to prevent indefinite hangs (2 minutes for credentials/refresh, 15 minutes
for device code flow).
"""
def __init__(
self,
address: str,
*,
codec: Codec | None = _PROTO_BINARY_CODEC,
protocol: ProtocolType = ProtocolType.CONNECT,
accept_compression: Iterable[Compression] | None = None,
send_compression: Compression | None = _GZIP_COMPRESSION,
timeout_ms: int | None = None,
read_max_bytes: int | None = None,
interceptors: Iterable[Interceptor] = (),
http_client: Client | None = None,
) -> None:
super().__init__(
address=address,
codec=codec,
protocol=protocol,
accept_compression=accept_compression,
send_compression=send_compression,
timeout_ms=timeout_ms,
read_max_bytes=read_max_bytes,
interceptors=interceptors,
http_client=http_client,
)
[docs]
def login_credentials(
self,
request: CredentialsAuthRequest,
*,
headers: Headers | Mapping[str, str] | None = None,
timeout_ms: int | None = None,
) -> AsyncIterator[CredentialsAuthResponse]:
"""
Authenticates one or more Minecraft accounts using credentials or tokens.
Supports bulk authentication with concurrent processing.
Results are streamed back as each authentication completes:
1. For each account, either a one_success (with account data) or
one_failure message is sent
2. A CredentialsAuthEnd message is sent when all checks are complete
Concurrency is controlled by the instance's ACCOUNT_IMPORT_CONCURRENCY setting.
Errors:
- NOT_FOUND: The specified instance does not exist
- PERMISSION_DENIED: Caller lacks AUTHENTICATE_MC_ACCOUNT permission
- INTERNAL: Authentication error (logged server-side with details)
Timeout: 2 minutes per account
"""
return self.execute_server_stream(
request=request,
method=MethodInfo(
name="LoginCredentials",
service_name="soulfire.v1.MCAuthService",
input=CredentialsAuthRequest,
output=CredentialsAuthResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.SERVER_STREAM,
),
headers=headers,
timeout_ms=timeout_ms,
)
[docs]
def login_device_code(
self,
request: DeviceCodeAuthRequest,
*,
headers: Headers | Mapping[str, str] | None = None,
timeout_ms: int | None = None,
) -> AsyncIterator[DeviceCodeAuthResponse]:
"""
Authenticates a Minecraft account using the Microsoft OAuth device code flow.
This is an interactive flow that requires user action in a web browser.
The stream first sends a DeviceCode message containing the verification
URL and user code. The client should display this to the user. Once the
user completes authorization in their browser, the stream sends the
authenticated account and completes.
Errors:
- NOT_FOUND: The specified instance does not exist
- PERMISSION_DENIED: Caller lacks AUTHENTICATE_MC_ACCOUNT permission
- INTERNAL: Authentication error (e.g., user denied access, timeout)
Timeout: 15 minutes (Microsoft device codes typically expire after this)
"""
return self.execute_server_stream(
request=request,
method=MethodInfo(
name="LoginDeviceCode",
service_name="soulfire.v1.MCAuthService",
input=DeviceCodeAuthRequest,
output=DeviceCodeAuthResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.SERVER_STREAM,
),
headers=headers,
timeout_ms=timeout_ms,
)
[docs]
async def refresh(
self,
request: RefreshRequest,
*,
headers: Headers | Mapping[str, str] | None = None,
timeout_ms: int | None = None,
) -> RefreshResponse:
"""
Refreshes the authentication tokens for an existing Minecraft account.
Used to renew expired access tokens using stored refresh tokens.
For Microsoft accounts, this refreshes the Minecraft token, profile,
and player certificates. For offline accounts, returns the account
unchanged (offline accounts never expire).
Errors:
- NOT_FOUND: The specified instance does not exist
- PERMISSION_DENIED: Caller lacks AUTHENTICATE_MC_ACCOUNT permission
- INTERNAL: Refresh error (e.g., refresh token expired or revoked)
Timeout: 2 minutes
"""
return await self.execute_unary(
request=request,
method=MethodInfo(
name="Refresh",
service_name="soulfire.v1.MCAuthService",
input=RefreshRequest,
output=RefreshResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.UNARY,
),
headers=headers,
timeout_ms=timeout_ms,
)
[docs]
class MCAuthServiceSync(Protocol):
"""
Service for authenticating Minecraft accounts for use with SoulFire bots.
Supports multiple authentication methods including Microsoft OAuth (credentials
and device code flows) and offline mode. All methods require the caller to
have AUTHENTICATE_MC_ACCOUNT permission for the target instance.
Authentication may optionally use proxies if configured in instance settings
(USE_PROXIES_FOR_ACCOUNT_AUTH). All authentication operations have timeouts
to prevent indefinite hangs (2 minutes for credentials/refresh, 15 minutes
for device code flow).
"""
[docs]
def login_credentials(self, request: CredentialsAuthRequest, ctx: RequestContext[CredentialsAuthRequest, CredentialsAuthResponse], /) -> Iterator[CredentialsAuthResponse]:
"""
Authenticates one or more Minecraft accounts using credentials or tokens.
Supports bulk authentication with concurrent processing.
Results are streamed back as each authentication completes:
1. For each account, either a one_success (with account data) or
one_failure message is sent
2. A CredentialsAuthEnd message is sent when all checks are complete
Concurrency is controlled by the instance's ACCOUNT_IMPORT_CONCURRENCY setting.
Errors:
- NOT_FOUND: The specified instance does not exist
- PERMISSION_DENIED: Caller lacks AUTHENTICATE_MC_ACCOUNT permission
- INTERNAL: Authentication error (logged server-side with details)
Timeout: 2 minutes per account
"""
raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs]
def login_device_code(self, request: DeviceCodeAuthRequest, ctx: RequestContext[DeviceCodeAuthRequest, DeviceCodeAuthResponse], /) -> Iterator[DeviceCodeAuthResponse]:
"""
Authenticates a Minecraft account using the Microsoft OAuth device code flow.
This is an interactive flow that requires user action in a web browser.
The stream first sends a DeviceCode message containing the verification
URL and user code. The client should display this to the user. Once the
user completes authorization in their browser, the stream sends the
authenticated account and completes.
Errors:
- NOT_FOUND: The specified instance does not exist
- PERMISSION_DENIED: Caller lacks AUTHENTICATE_MC_ACCOUNT permission
- INTERNAL: Authentication error (e.g., user denied access, timeout)
Timeout: 15 minutes (Microsoft device codes typically expire after this)
"""
raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs]
def refresh(self, request: RefreshRequest, ctx: RequestContext[RefreshRequest, RefreshResponse], /) -> RefreshResponse:
"""
Refreshes the authentication tokens for an existing Minecraft account.
Used to renew expired access tokens using stored refresh tokens.
For Microsoft accounts, this refreshes the Minecraft token, profile,
and player certificates. For offline accounts, returns the account
unchanged (offline accounts never expire).
Errors:
- NOT_FOUND: The specified instance does not exist
- PERMISSION_DENIED: Caller lacks AUTHENTICATE_MC_ACCOUNT permission
- INTERNAL: Refresh error (e.g., refresh token expired or revoked)
Timeout: 2 minutes
"""
raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs]
class MCAuthServiceWSGIApplication(ConnectWSGIApplication):
def __init__(
self,
service: MCAuthServiceSync,
interceptors: Iterable[InterceptorSync] = (),
read_max_bytes: int | None = DEFAULT_READ_MAX_BYTES,
compressions: Iterable[Compression] | None = None,
codecs: Iterable[Codec] | None = _DEFAULT_CODECS,
) -> None:
super().__init__(
endpoints={
"/soulfire.v1.MCAuthService/LoginCredentials": EndpointSync.server_stream(
method=MethodInfo(
name="LoginCredentials",
service_name="soulfire.v1.MCAuthService",
input=CredentialsAuthRequest,
output=CredentialsAuthResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.SERVER_STREAM,
),
function=service.login_credentials,
),
"/soulfire.v1.MCAuthService/LoginDeviceCode": EndpointSync.server_stream(
method=MethodInfo(
name="LoginDeviceCode",
service_name="soulfire.v1.MCAuthService",
input=DeviceCodeAuthRequest,
output=DeviceCodeAuthResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.SERVER_STREAM,
),
function=service.login_device_code,
),
"/soulfire.v1.MCAuthService/Refresh": EndpointSync.unary(
method=MethodInfo(
name="Refresh",
service_name="soulfire.v1.MCAuthService",
input=RefreshRequest,
output=RefreshResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.UNARY,
),
function=service.refresh,
),
},
interceptors=interceptors,
read_max_bytes=read_max_bytes,
compressions=compressions,
codecs=codecs,
)
@property
def path(self) -> str:
"""Returns the URL path to mount the application to when serving multiple applications."""
return "/soulfire.v1.MCAuthService"
[docs]
class MCAuthServiceClientSync(ConnectClientSync):
"""
Service for authenticating Minecraft accounts for use with SoulFire bots.
Supports multiple authentication methods including Microsoft OAuth (credentials
and device code flows) and offline mode. All methods require the caller to
have AUTHENTICATE_MC_ACCOUNT permission for the target instance.
Authentication may optionally use proxies if configured in instance settings
(USE_PROXIES_FOR_ACCOUNT_AUTH). All authentication operations have timeouts
to prevent indefinite hangs (2 minutes for credentials/refresh, 15 minutes
for device code flow).
"""
def __init__(
self,
address: str,
*,
codec: Codec | None = _PROTO_BINARY_CODEC,
protocol: ProtocolType = ProtocolType.CONNECT,
accept_compression: Iterable[Compression] | None = None,
send_compression: Compression | None = _GZIP_COMPRESSION,
timeout_ms: int | None = None,
read_max_bytes: int | None = None,
interceptors: Iterable[InterceptorSync] = (),
http_client: SyncClient | None = None,
) -> None:
super().__init__(
address=address,
codec=codec,
protocol=protocol,
accept_compression=accept_compression,
send_compression=send_compression,
timeout_ms=timeout_ms,
read_max_bytes=read_max_bytes,
interceptors=interceptors,
http_client=http_client,
)
[docs]
def login_credentials(
self,
request: CredentialsAuthRequest,
*,
headers: Headers | Mapping[str, str] | None = None,
timeout_ms: int | None = None,
) -> Iterator[CredentialsAuthResponse]:
"""
Authenticates one or more Minecraft accounts using credentials or tokens.
Supports bulk authentication with concurrent processing.
Results are streamed back as each authentication completes:
1. For each account, either a one_success (with account data) or
one_failure message is sent
2. A CredentialsAuthEnd message is sent when all checks are complete
Concurrency is controlled by the instance's ACCOUNT_IMPORT_CONCURRENCY setting.
Errors:
- NOT_FOUND: The specified instance does not exist
- PERMISSION_DENIED: Caller lacks AUTHENTICATE_MC_ACCOUNT permission
- INTERNAL: Authentication error (logged server-side with details)
Timeout: 2 minutes per account
"""
return self.execute_server_stream(
request=request,
method=MethodInfo(
name="LoginCredentials",
service_name="soulfire.v1.MCAuthService",
input=CredentialsAuthRequest,
output=CredentialsAuthResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.SERVER_STREAM,
),
headers=headers,
timeout_ms=timeout_ms,
)
[docs]
def login_device_code(
self,
request: DeviceCodeAuthRequest,
*,
headers: Headers | Mapping[str, str] | None = None,
timeout_ms: int | None = None,
) -> Iterator[DeviceCodeAuthResponse]:
"""
Authenticates a Minecraft account using the Microsoft OAuth device code flow.
This is an interactive flow that requires user action in a web browser.
The stream first sends a DeviceCode message containing the verification
URL and user code. The client should display this to the user. Once the
user completes authorization in their browser, the stream sends the
authenticated account and completes.
Errors:
- NOT_FOUND: The specified instance does not exist
- PERMISSION_DENIED: Caller lacks AUTHENTICATE_MC_ACCOUNT permission
- INTERNAL: Authentication error (e.g., user denied access, timeout)
Timeout: 15 minutes (Microsoft device codes typically expire after this)
"""
return self.execute_server_stream(
request=request,
method=MethodInfo(
name="LoginDeviceCode",
service_name="soulfire.v1.MCAuthService",
input=DeviceCodeAuthRequest,
output=DeviceCodeAuthResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.SERVER_STREAM,
),
headers=headers,
timeout_ms=timeout_ms,
)
[docs]
def refresh(
self,
request: RefreshRequest,
*,
headers: Headers | Mapping[str, str] | None = None,
timeout_ms: int | None = None,
) -> RefreshResponse:
"""
Refreshes the authentication tokens for an existing Minecraft account.
Used to renew expired access tokens using stored refresh tokens.
For Microsoft accounts, this refreshes the Minecraft token, profile,
and player certificates. For offline accounts, returns the account
unchanged (offline accounts never expire).
Errors:
- NOT_FOUND: The specified instance does not exist
- PERMISSION_DENIED: Caller lacks AUTHENTICATE_MC_ACCOUNT permission
- INTERNAL: Refresh error (e.g., refresh token expired or revoked)
Timeout: 2 minutes
"""
return self.execute_unary(
request=request,
method=MethodInfo(
name="Refresh",
service_name="soulfire.v1.MCAuthService",
input=RefreshRequest,
output=RefreshResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.UNARY,
),
headers=headers,
timeout_ms=timeout_ms,
)