Esempio n. 1
0
        // GET api/<controller>
        public HttpResponseMessage Get()
        {
            if (ServerUtil.Config().Domain == "")
            {
                ServerUtil.Config().Domain = Request.RequestUri.Authority;
                ServerUtil.Config().Save();
            }
            var response = ServerUtil.returnStatus(HttpStatusCode.OK, "Success");

            response.Content = new StringContent(ServerUtil.AuthenticationKey());
            return(response);
        }
Esempio n. 2
0
        // GET api/<controller>/5
        public HttpResponseMessage Get(string id)
        {
            HttpResponseMessage response;

            switch (id.ToLower())
            {
            case "key":
                response         = ServerUtil.returnStatus(HttpStatusCode.OK, "Success");
                response.Content = new StringContent(ServerUtil.AuthenticationKey());
                break;

            default:
                response = ServerUtil.returnStatus(HttpStatusCode.BadRequest, "Invalid Request");
                break;
            }
            return(response);
        }
Esempio n. 3
0
        // POST api/<controller>
        public HttpResponseMessage Post([FromBody] AuthInfo info)
        {
            try
            {
                var clients = ClientIdentity.Select(id => id.ClientID == info.ClientID).ToList();

                if (clients.Count == 0)
                {
                    return(ServerUtil.returnStatus(HttpStatusCode.Unauthorized, "Authorization Failed"));
                }

                var client = clients[0];
                if (WopiSecurity.MD5Encrypt(client.ClientSecret + ServerUtil.AuthenticationKey()) == info.SecureString)
                {
                    var response = ServerUtil.returnStatus(HttpStatusCode.OK, "Success");

                    client.Token   = WopiSecurity.MD5Encrypt(Guid.NewGuid().ToString());
                    client.Counter = 1;

                    client.Save();

                    response.Content = new StringContent(client.Token);

                    return(response);
                }
                else
                {
                    return(ServerUtil.returnStatus(HttpStatusCode.Unauthorized, "Authorization Failed"));
                }
            }
            catch (Exception ex)
            {
                ServerUtil.LogException(ex);
                return(ServerUtil.returnStatus(HttpStatusCode.BadRequest, "Invalid Request"));
            }
        }