dd4650a
use crate::session::{RequestId, Session};
use actix_web::web;
use crate::auth::AuthSvc;
use crate::auth::challenge::types::ChallengeResponse;
use crate::auth::errors::AuthError;
use crate::envelope::Envelope;
use crate::envelope::NoData;
#[utoipa::path(
post,
path = "/api/v1/oauth/challenge",
tag = "auth",
operation_id = "auth_challenge",
summary = "签发工作量证明挑战",
description = "把挑战写进当前会话并返回。客户端需要为 `context` 找出一枚满足 `difficulty`(前导零比特数)的 nonce;`pow.v1` 算法与前端求解器一致。",
responses(
(
status = 200,
description = "挑战已签发并写入会话",
body = Envelope<ChallengeResponse>,
example = json!({"code":200,"message":"success","data":{"context":"3xJk9Qp2mV7sLbT1rZa8nHc4wDf6YgU0","difficulty":16,"issued_at":1767139200,"expires_at":1767139500}})
),
(
status = 500,
description = "`internal`(挑战无法写入会话)/ `cache` / `session` / `serialization`",
body = Envelope<NoData>,
example = json!({"code": "internal", "message": "internal server error"})
)
)
)]
pub async fn challenge(
svc: web::Data<AuthSvc>,
session: Session,
request_id: RequestId,
) -> Result<Envelope<ChallengeResponse>, AuthError> {
let challenge = svc.challenge(session, request_id.0).await?;
Ok(Envelope::ok(challenge))
}