package com.yonge.cooleshow.common.util;

import com.yonge.toolset.base.string.StringPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.oauth2.common.exceptions.UnapprovedClientAuthenticationException;

/**
 * 认证工具类
 */
public class TokenUtil {

    private final static Logger log = LoggerFactory.getLogger(TokenUtil.class);

    public final static String HEADER_KEY = "Authorization";
    public final static String HEADER_PREFIX = "bearer ";

    /**
     * 解码
     */
    public static String getToken() {
        String header = WebUtil.getRequest().getHeader(TokenUtil.HEADER_KEY);
        if (header == null || !header.startsWith(TokenUtil.HEADER_PREFIX)) {
            throw new UnapprovedClientAuthenticationException("请求头中无client信息");
        }
        return header.replace(HEADER_PREFIX,StringPool.EMPTY);
    }

}
