package org.lingniu.idp.security.converter;

import jakarta.servlet.http.HttpServletRequest;
import org.lingniu.idp.security.token.SmsCodeAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationConverter;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class SmsCodeAuthenticationConverter implements AuthenticationConverter {
    
    @Override
    public Authentication convert(HttpServletRequest request) {
        // 从请求参数中获取手机号和验证码
        String phone = request.getParameter("phone");
        String code = request.getParameter("code");
        
        if (StringUtils.hasText(phone) && StringUtils.hasText(code)) {
            return new SmsCodeAuthenticationToken(phone, code);
        }
        
        return null;
    }
}