我正在ASP.NET WebAPI中实现基于令牌的身份验证 . 是否可以在WebAPI 1.2中实现承载令牌认证?

update:

问题是我看到的所有示例都基于WebAPI 2和OWIN . WebAPI 2提出了一个专用的身份验证属性,但我正在寻找WebAPI 1.2它只具有授权属性 . 我们需要覆盖onAuthorize方法并实现令牌验证逻辑 . 但我不知道如何实现承载令牌并设置该令牌的到期时间 . 如果令牌过期,如何生成新令牌 . 某处我需要存储生成的令牌才能验证?

public class APIAuthentication : AuthorizationFilterAttribute
{
    private const string BasicAuthResponseHeader = "WWW-Authenticate";
    private const string BasicAuthResponseHeaderValue = "Basic";

    public override void OnAuthorization(HttpActionContext actionContext)
    {
        //logics for perform bearer token auth.
        //if auth failed we ill be return 401 and auth type in header
        HandleUnAuthorized(actionContext);
    }

    private void HandleUnAuthorized(HttpActionContext actionContext)
    {
        actionContext.Response = actionContext.ControllerContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
        actionContext.Response.Headers.Add(BasicAuthResponseHeader, BasicAuthResponseHeaderValue);
    }
}

谢谢,Gowrish .