class LookoutTokenResolveUtils {

    public static String getLookoutToken(ServerRequest.Headers headers) {
        String token = WebfluxUtils.getHeaderValue(headers, Constants.TOKEN_HEADER_NAME);
        if (token == null) {
            String authorization = WebfluxUtils.getHeaderValue(headers, "Authorization");
            // 按照下面的方式反解出token即可
            // Authorization: Basic: base64(token:)
            if (StringUtils.startsWith(authorization, "Basic ")) {
                String base64 = authorization.substring(6);
                String usernameAndPassword = new String(Base64.getUrlDecoder().decode(base64),
                    StandardCharsets.UTF_8);
                String username = StringUtils.substringBefore(usernameAndPassword, ":");
                // 如果 username 是 lookout 那么以 password 作为token
                // 否则 username 用户名作为token
                if ("lookout".equals(username)) {
                    String password = StringUtils.substringAfter(usernameAndPassword, ":");
                    token = password;
                } else {
                    token = username;
                }
            }
        }
        return token;
    }

    private  LookoutTokenResolveUtils();

}