是否有可能以某种方式使用此类(test.Value不是我正在寻找的):
app.UseAuthQSTokenExtractor();
这是课堂主体:
namespace Owin
{
public static class AuthorizationQSTokenExtractorExtension
{
public static void UseAuthQSTokenExtractor(this IAppBuilder app)
{
app.Use<AuthorizationQsTokenExtractorMiddleware>();
}
}
}
namespace Chat.Middleware
{
public class AuthorizationQsTokenExtractorMiddleware : OwinMiddleware
{
public AuthorizationQsTokenExtractorMiddleware(OwinMiddleware next)
: base(next)
{
}
public override async Task Invoke(IOwinContext context)
{
Debug.WriteLine("signalr-auth-middleware");
string bearerToken = context.Request.Query.Get("access_token");
Debug.WriteLine("signar-bearer: " + bearerToken);
if (bearerToken != null)
{
TokenHelper.DecodeAndWrite(bearerToken);
string[] authorization = { "Bearer " + bearerToken };
context.Request.Headers.Add("Authorization", authorization);
}
await Next.Invoke(context);
}
}
答案 0 :(得分:2)
是的,如果您重载true
和false
运营商:
// note: you might want to think about what `null` means in terms of true/false
public static bool operator true(RefBool val) => val.Value;
public static bool operator false(RefBool val) => !val.Value;
但是,我不确定这是个好主意。 ref bool
似乎更明显。