
    i                        d Z ddlmZ ddlmZmZmZ ddlmZ ddlm	Z	m
Z
 ddlmZ  G d de	          Z G d	 d
e	          ZdddddZdS )u   JWT token creation utility.

JWT 令牌生成工具模块。
提供统一的令牌创建函数，供 SSO 认证和 Mock 测试端点复用。
    )annotations)datetime	timedeltatimezone)jwt)	BaseModelField)settingsc                      e Zd ZU dZded<   dZded<   dZded<   dZded<   dZded<   dZ	ded	<   dZ
ded
<   dZded<    ee          Zded<   dS )TokenClaimsuf   Input claims for token generation.

    令牌生成的输入参数，包含用户身份信息。
    struser_id 	user_name	office_idoffice_namedept_id	dept_namearea_id	area_name)default_factoryz	list[str]role_idsN)__name__
__module____qualname____doc____annotations__r   r   r   r   r   r   r   r	   listr        +D:\work\zm-rag\backend\app\core\security.pyr   r      s          
 LLLIIKGIGI%555H555555r    r   c                  (    e Zd ZU dZded<   ded<   dS )TokenResultug   Output of token generation.

    令牌生成的输出，包含签名后的 JWT 和过期时间。
    r   access_tokenint
expires_inN)r   r   r   r   r   r   r    r!   r#   r#   "   s1          
 OOOOOr    r#   i  zzm-rag)expires_minutesissuerclaimsr'   r%   r(   r   returnc                  t          j        t          j                  }|t	          |          z   }| j        | j        | j        | j        | j	        | j
        | j        | j        | j        t          |                                          t          |                                          |d}t!          j        |t$          j        t$          j                  }t+          ||dz            S )uw  Create a signed JWT from the given claims.

    根据用户身份信息创建签名的 JWT 令牌。

    Args:
        claims: User identity claims to embed in the token.
        expires_minutes: Token lifetime in minutes (default 24 hours).
        issuer: Value for the ``iss`` claim.

    Returns:
        TokenResult with the encoded JWT and expiration in seconds.
    )tz)minutes)subr   r   r   r   r   r   r   r   iatexpiss)	algorithm<   )r$   r&   )r   nowr   utcr   r   r   r   r   r   r   r   r   r   r%   	timestampr   encoder
   
jwt_secretjwt_algorithmr#   )r)   r'   r(   r4   expirepayloadtokens          r!   create_access_tokenr=   ,   s    $ ,(,
'
'
'C9_5555F ~%%)>%>%O3==??##6##%%&& G Jw 3x?UVVVE"R'   r    N)r)   r   r'   r%   r(   r   r*   r#   )r   
__future__r   r   r   r   joser   pydanticr   r	   
app.configr
   r   r#   r=   r   r    r!   <module>rB      s    # " " " " " 2 2 2 2 2 2 2 2 2 2       % % % % % % % %      6 6 6 6 6) 6 6 6"    )     	) ) ) ) ) ) ) )r    