Inheritance: LetMeRate.Application.Security.WithAccountContext
        public AuthorisationModule(IAuthorisationService authorisationService)
        {
            this.authorisationService = authorisationService;

            Post["/{Key}/Authorisation"] = x =>
            {
                var command = new AuthorisationCredentialsCommand(new AccountContext(x.Key), IPAddress.Parse(Request.Form.IPAddress));
                var authorisation = authorisationService.CreateAuthorisationToken(command);
                return Response.AsJson(new
                {
                    authorisation.TokenKey
                });
            };
        }
        public dynamic CreateAuthorisationToken(AuthorisationCredentialsCommand command)
        {
            var userAccount = GetUserAccount(command.AccountContext.AccountKey);
            var authToken = new AuthorisationToken(command.IpAddress);

            dynamic authorisation = new ExpandoObject();
            authorisation.Id = Guid.NewGuid();
            authorisation.UserAccountId = userAccount.Id;
            authorisation.IPAddress = authToken.IPAddress;
            authorisation.TokenExpiry = authToken.Expiry;
            authorisation.TokenKey = authToken.TokenKey;

            var db = Database.Open();
            db.Authorisations.Insert(authorisation);
            return authorisation;
        }