Ejemplo n.º 1
0
        public object UpdateToken([FromBody] TokenConfigContext ctx)
        {
            var authInfo = auth.GetAuthorizationInfo(ctx.Token);

            if (authInfo != null)
            {
                var user = DataService.GetServiceUser(authInfo.UserName);
                if (user != null)
                {
                    var md5Rslt = CalcMd5(authInfo.UserName, ctx.Random, user.ApiKey);
                    if (System.String.Compare(md5Rslt, ctx.Sig, System.StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        var dateOffset = authInfo.Expire - DateTimeOffset.Now;
                        if (dateOffset.TotalMinutes > 0 && dateOffset.TotalMinutes < 10)
                        {
                            auth.UpdateAuthorizationInfo(ctx.Token, DefaultDuration);
                            return(this.Request.CreateResponse(
                                       HttpStatusCode.Accepted,
                                       new JObject(new JProperty("res", true))));
                        }
                    }
                }
            }

            return(this.Request.CreateResponse(
                       HttpStatusCode.Accepted,
                       new JObject(new JProperty("res", false))));
        }
Ejemplo n.º 2
0
        public object DropToken([FromBody] TokenConfigContext ctx)
        {
            var authInfo = auth.GetAuthorizationInfo(ctx.Token);

            if (authInfo != null)
            {
                var user = DataService.GetServiceUser(authInfo.UserName);
                if (user != null)
                {
                    var md5Rslt = CalcMd5(authInfo.UserName, ctx.Random, user.ApiKey);
                    if (System.String.Compare(md5Rslt, ctx.Sig, System.StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        auth.RemoveVerifyTicket(ctx.Token);

                        return(this.Request.CreateResponse(
                                   HttpStatusCode.Accepted,
                                   new JObject(new JProperty("res", true))));
                    }
                }
            }

            return(this.Request.CreateResponse(
                       HttpStatusCode.Accepted,
                       new JObject(new JProperty("res", false))));
        }