예제 #1
0
        public void TokenAuthenticationTest()
        {
            // Create application in case it doesn't exist
            var app = InsertApplication();

            DataLib.Repository repo = new DataLib.Repository();
            var token = repo.GenerateToken(app.Application_Id);

            Assert.IsTrue(repo.CheckTokenAuthentication(token.Token));
        }
        public override void OnActionExecuting(HttpActionContext filterContext)
        {
            var repo      = new DataLib.Repository();
            var authToken = this.FetchAuthHeader(filterContext);

            if (authToken == null)
            {
                filterContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
            }
            else if (!repo.CheckTokenAuthentication(authToken))
            {
                var responseMessage = new HttpResponseMessage(HttpStatusCode.Forbidden)
                {
                    ReasonPhrase = "Invalid Request"
                };
                filterContext.Response = responseMessage;
            }
            base.OnActionExecuting(filterContext);
        }