# Generated from soulfire/login.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 .login_pb2 import EmailCodeRequest, LoginRequest, NextAuthFlowResponse
if TYPE_CHECKING:
from collections.abc import AsyncGenerator, Iterable, 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 LoginService(Protocol):
"""
Service for authenticating users via email-based passwordless login.
Authentication Flow:
1. Client calls Login with the user's email address
2. If the email is registered, a six-digit code is sent to that email
3. Client receives an auth_flow_token and EmailCode response
4. User enters the code from their email
5. Client calls EmailCode with the auth_flow_token and the code
6. If valid, client receives a JWT token; if invalid, receives a Failure
Security Features:
- Rate limited to 20 requests per 10 minutes per origin to prevent brute force attacks
- Auth flow tokens expire after 15 minutes
- Same response for registered and unregistered emails to prevent email enumeration
- Invalid codes return the same error as expired/invalid flow tokens to prevent timing attacks
Error Handling:
- RESOURCE_EXHAUSTED: Rate limit exceeded (too many login attempts)
- UNAUTHENTICATED: No origin header provided (required for rate limiting)
- INTERNAL: Unexpected server error during processing
"""
[docs]
async def login(self, request: LoginRequest, ctx: RequestContext[LoginRequest, NextAuthFlowResponse], /) -> NextAuthFlowResponse:
"""
Initiates a login flow for the specified email address.
If the email is registered, a six-digit verification code is sent to that address.
The response always indicates that an email code step is next, regardless of whether
the email exists, to prevent email enumeration attacks.
Returns:
- NextAuthFlowResponse with email_code set and a new auth_flow_token
Errors:
- RESOURCE_EXHAUSTED: Too many login attempts from this origin
- UNAUTHENTICATED: Missing origin header
- INTERNAL: Server error (e.g., database or email sending failure)
"""
raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs]
async def email_code(self, request: EmailCodeRequest, ctx: RequestContext[EmailCodeRequest, NextAuthFlowResponse], /) -> NextAuthFlowResponse:
"""
Verifies an email verification code to complete authentication.
The auth_flow_token must match a pending login flow, and the code must match
the one that was sent to the user's email. On success, returns a JWT token.
On failure, returns a Failure response with INVALID_CODE reason.
After successful verification, the auth_flow_token is invalidated and cannot be reused.
Returns:
- NextAuthFlowResponse with success set (containing JWT token) if code is valid
- NextAuthFlowResponse with failure set (INVALID_CODE reason) if code is invalid
Errors:
- RESOURCE_EXHAUSTED: Too many login attempts from this origin
- UNAUTHENTICATED: Missing origin header
- INTERNAL: Server error (e.g., JWT generation failure)
"""
raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs]
class LoginServiceASGIApplication(ConnectASGIApplication[LoginService]):
def __init__(
self,
service: LoginService | AsyncGenerator[LoginService],
*,
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.LoginService/Login": Endpoint.unary(
method=MethodInfo(
name="Login",
service_name="soulfire.v1.LoginService",
input=LoginRequest,
output=NextAuthFlowResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.UNARY,
),
function=svc.login,
),
"/soulfire.v1.LoginService/EmailCode": Endpoint.unary(
method=MethodInfo(
name="EmailCode",
service_name="soulfire.v1.LoginService",
input=EmailCodeRequest,
output=NextAuthFlowResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.UNARY,
),
function=svc.email_code,
),
},
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.LoginService"
[docs]
class LoginServiceClient(ConnectClient):
"""
Service for authenticating users via email-based passwordless login.
Authentication Flow:
1. Client calls Login with the user's email address
2. If the email is registered, a six-digit code is sent to that email
3. Client receives an auth_flow_token and EmailCode response
4. User enters the code from their email
5. Client calls EmailCode with the auth_flow_token and the code
6. If valid, client receives a JWT token; if invalid, receives a Failure
Security Features:
- Rate limited to 20 requests per 10 minutes per origin to prevent brute force attacks
- Auth flow tokens expire after 15 minutes
- Same response for registered and unregistered emails to prevent email enumeration
- Invalid codes return the same error as expired/invalid flow tokens to prevent timing attacks
Error Handling:
- RESOURCE_EXHAUSTED: Rate limit exceeded (too many login attempts)
- UNAUTHENTICATED: No origin header provided (required for rate limiting)
- INTERNAL: Unexpected server error during processing
"""
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]
async def login(
self,
request: LoginRequest,
*,
headers: Headers | Mapping[str, str] | None = None,
timeout_ms: int | None = None,
) -> NextAuthFlowResponse:
"""
Initiates a login flow for the specified email address.
If the email is registered, a six-digit verification code is sent to that address.
The response always indicates that an email code step is next, regardless of whether
the email exists, to prevent email enumeration attacks.
Returns:
- NextAuthFlowResponse with email_code set and a new auth_flow_token
Errors:
- RESOURCE_EXHAUSTED: Too many login attempts from this origin
- UNAUTHENTICATED: Missing origin header
- INTERNAL: Server error (e.g., database or email sending failure)
"""
return await self.execute_unary(
request=request,
method=MethodInfo(
name="Login",
service_name="soulfire.v1.LoginService",
input=LoginRequest,
output=NextAuthFlowResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.UNARY,
),
headers=headers,
timeout_ms=timeout_ms,
)
[docs]
async def email_code(
self,
request: EmailCodeRequest,
*,
headers: Headers | Mapping[str, str] | None = None,
timeout_ms: int | None = None,
) -> NextAuthFlowResponse:
"""
Verifies an email verification code to complete authentication.
The auth_flow_token must match a pending login flow, and the code must match
the one that was sent to the user's email. On success, returns a JWT token.
On failure, returns a Failure response with INVALID_CODE reason.
After successful verification, the auth_flow_token is invalidated and cannot be reused.
Returns:
- NextAuthFlowResponse with success set (containing JWT token) if code is valid
- NextAuthFlowResponse with failure set (INVALID_CODE reason) if code is invalid
Errors:
- RESOURCE_EXHAUSTED: Too many login attempts from this origin
- UNAUTHENTICATED: Missing origin header
- INTERNAL: Server error (e.g., JWT generation failure)
"""
return await self.execute_unary(
request=request,
method=MethodInfo(
name="EmailCode",
service_name="soulfire.v1.LoginService",
input=EmailCodeRequest,
output=NextAuthFlowResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.UNARY,
),
headers=headers,
timeout_ms=timeout_ms,
)
[docs]
class LoginServiceSync(Protocol):
"""
Service for authenticating users via email-based passwordless login.
Authentication Flow:
1. Client calls Login with the user's email address
2. If the email is registered, a six-digit code is sent to that email
3. Client receives an auth_flow_token and EmailCode response
4. User enters the code from their email
5. Client calls EmailCode with the auth_flow_token and the code
6. If valid, client receives a JWT token; if invalid, receives a Failure
Security Features:
- Rate limited to 20 requests per 10 minutes per origin to prevent brute force attacks
- Auth flow tokens expire after 15 minutes
- Same response for registered and unregistered emails to prevent email enumeration
- Invalid codes return the same error as expired/invalid flow tokens to prevent timing attacks
Error Handling:
- RESOURCE_EXHAUSTED: Rate limit exceeded (too many login attempts)
- UNAUTHENTICATED: No origin header provided (required for rate limiting)
- INTERNAL: Unexpected server error during processing
"""
[docs]
def login(self, request: LoginRequest, ctx: RequestContext[LoginRequest, NextAuthFlowResponse], /) -> NextAuthFlowResponse:
"""
Initiates a login flow for the specified email address.
If the email is registered, a six-digit verification code is sent to that address.
The response always indicates that an email code step is next, regardless of whether
the email exists, to prevent email enumeration attacks.
Returns:
- NextAuthFlowResponse with email_code set and a new auth_flow_token
Errors:
- RESOURCE_EXHAUSTED: Too many login attempts from this origin
- UNAUTHENTICATED: Missing origin header
- INTERNAL: Server error (e.g., database or email sending failure)
"""
raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs]
def email_code(self, request: EmailCodeRequest, ctx: RequestContext[EmailCodeRequest, NextAuthFlowResponse], /) -> NextAuthFlowResponse:
"""
Verifies an email verification code to complete authentication.
The auth_flow_token must match a pending login flow, and the code must match
the one that was sent to the user's email. On success, returns a JWT token.
On failure, returns a Failure response with INVALID_CODE reason.
After successful verification, the auth_flow_token is invalidated and cannot be reused.
Returns:
- NextAuthFlowResponse with success set (containing JWT token) if code is valid
- NextAuthFlowResponse with failure set (INVALID_CODE reason) if code is invalid
Errors:
- RESOURCE_EXHAUSTED: Too many login attempts from this origin
- UNAUTHENTICATED: Missing origin header
- INTERNAL: Server error (e.g., JWT generation failure)
"""
raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs]
class LoginServiceWSGIApplication(ConnectWSGIApplication):
def __init__(
self,
service: LoginServiceSync,
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.LoginService/Login": EndpointSync.unary(
method=MethodInfo(
name="Login",
service_name="soulfire.v1.LoginService",
input=LoginRequest,
output=NextAuthFlowResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.UNARY,
),
function=service.login,
),
"/soulfire.v1.LoginService/EmailCode": EndpointSync.unary(
method=MethodInfo(
name="EmailCode",
service_name="soulfire.v1.LoginService",
input=EmailCodeRequest,
output=NextAuthFlowResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.UNARY,
),
function=service.email_code,
),
},
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.LoginService"
[docs]
class LoginServiceClientSync(ConnectClientSync):
"""
Service for authenticating users via email-based passwordless login.
Authentication Flow:
1. Client calls Login with the user's email address
2. If the email is registered, a six-digit code is sent to that email
3. Client receives an auth_flow_token and EmailCode response
4. User enters the code from their email
5. Client calls EmailCode with the auth_flow_token and the code
6. If valid, client receives a JWT token; if invalid, receives a Failure
Security Features:
- Rate limited to 20 requests per 10 minutes per origin to prevent brute force attacks
- Auth flow tokens expire after 15 minutes
- Same response for registered and unregistered emails to prevent email enumeration
- Invalid codes return the same error as expired/invalid flow tokens to prevent timing attacks
Error Handling:
- RESOURCE_EXHAUSTED: Rate limit exceeded (too many login attempts)
- UNAUTHENTICATED: No origin header provided (required for rate limiting)
- INTERNAL: Unexpected server error during processing
"""
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(
self,
request: LoginRequest,
*,
headers: Headers | Mapping[str, str] | None = None,
timeout_ms: int | None = None,
) -> NextAuthFlowResponse:
"""
Initiates a login flow for the specified email address.
If the email is registered, a six-digit verification code is sent to that address.
The response always indicates that an email code step is next, regardless of whether
the email exists, to prevent email enumeration attacks.
Returns:
- NextAuthFlowResponse with email_code set and a new auth_flow_token
Errors:
- RESOURCE_EXHAUSTED: Too many login attempts from this origin
- UNAUTHENTICATED: Missing origin header
- INTERNAL: Server error (e.g., database or email sending failure)
"""
return self.execute_unary(
request=request,
method=MethodInfo(
name="Login",
service_name="soulfire.v1.LoginService",
input=LoginRequest,
output=NextAuthFlowResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.UNARY,
),
headers=headers,
timeout_ms=timeout_ms,
)
[docs]
def email_code(
self,
request: EmailCodeRequest,
*,
headers: Headers | Mapping[str, str] | None = None,
timeout_ms: int | None = None,
) -> NextAuthFlowResponse:
"""
Verifies an email verification code to complete authentication.
The auth_flow_token must match a pending login flow, and the code must match
the one that was sent to the user's email. On success, returns a JWT token.
On failure, returns a Failure response with INVALID_CODE reason.
After successful verification, the auth_flow_token is invalidated and cannot be reused.
Returns:
- NextAuthFlowResponse with success set (containing JWT token) if code is valid
- NextAuthFlowResponse with failure set (INVALID_CODE reason) if code is invalid
Errors:
- RESOURCE_EXHAUSTED: Too many login attempts from this origin
- UNAUTHENTICATED: Missing origin header
- INTERNAL: Server error (e.g., JWT generation failure)
"""
return self.execute_unary(
request=request,
method=MethodInfo(
name="EmailCode",
service_name="soulfire.v1.LoginService",
input=EmailCodeRequest,
output=NextAuthFlowResponse,
idempotency_level=IdempotencyLevel.UNKNOWN,
stream_type=StreamType.UNARY,
),
headers=headers,
timeout_ms=timeout_ms,
)