// MyAuthCheck is a sample authentication method, it will interact with AuthLayer (MSSQL database).
    public Task <Coprocess.Object> MyAuthCheck(Coprocess.Object thisObject, ServerCallContext context)
    {
        // Request.Headers contains all the request headers, we retrieve the authorization token:
        var token = thisObject.Request.Headers["Authorization"];

        Console.WriteLine("Calling MyAuthCheck with token = " + token);

        if (!AuthLayer.active)
        {
            Console.WriteLine("Rejecting auth! This sample requires a database.");
            return(Task.FromResult(thisObject));
        }

        // userData will be null if the authentication is wrong.
        var userData = AuthLayer.Authenticate(token);

        if (userData != null)
        {
            Console.WriteLine("Successful auth!");
            var session = new Coprocess.SessionState();
            session.Rate             = 1000;
            session.Per              = 10;
            session.QuotaMax         = 60;
            session.QuotaRenews      = 1479033599;
            session.QuotaRemaining   = 0;
            session.QuotaRenewalRate = 120;
            session.Expires          = 1479033599;

            session.LastUpdated = 1478033599.ToString();

            thisObject.Metadata["token"] = token;
            thisObject.Session           = session;
            return(Task.FromResult(thisObject));
        }

        Console.WriteLine("Rejecting auth!");
        return(Task.FromResult(thisObject));
    }
 public DispatcherImpl()
 {
     Console.WriteLine("Instantiating DispatcherImpl");
     AuthLayer.Init();
 }