public string Login([FromBody] UserInfo userInfo)
 {
     // Hardcoded Prüfung zur Veranschaulichung
     if ("admin".Equals(userInfo.username) && "admin".Equals(userInfo.password))
     {
         using (var ctx = new TokenDBContext())
         {
             Token tkn = new Token();
             tkn.serviceId = userInfo.serviceId;
             tkn.token     = Guid.NewGuid().ToString();
             Token current = ctx.Token.Find(userInfo.serviceId);
             if (current != null)
             {
                 ctx.Token.Remove(current);
                 ctx.SaveChanges();
             }
             ctx.Token.Add(tkn);
             ctx.SaveChanges();
             return(tkn.token);
         }
     }
     else
     {
         Response.StatusCode = StatusCodes.Status401Unauthorized;
         return(null);
     }
 }
Ejemplo n.º 2
0
        public string VerifyToken()
        {
            NameValueCollection parameters = new NameValueCollection(Request.QueryString);
            string strToken = parameters["token"];
            var    token    = tokenDb.Tokens
                              .Where(t => t.OAuthToken == strToken)
                              .FirstOrDefault();
            CanonicalRequestResponse req = new CanonicalRequestResponse();

            req.result = parameters["result"];
            req.token  = strToken;

            // this function has no actual use, it's there for the proof
            agnosticVerifyToken(req);

            if (token != null && token.EffectiveResult == "untossed")
            {
                token.EffectiveResult = parameters["result"];
                tokenDb.SaveChanges();

                return(token.EffectiveResult);
            }

            return("");
        }
Ejemplo n.º 3
0
        public ActionResult Create(Token token)
        {
            if (ModelState.IsValid)
            {
                db.Tokens.Add(token);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(token));
        }
Ejemplo n.º 4
0
        public string VerifyToken()
        {
            NameValueCollection parameters = new NameValueCollection(Request.QueryString);
            string strToken = parameters["token"];
            var    token    = tokenDb.Tokens
                              .Where(t => t.OAuthToken == strToken)
                              .FirstOrDefault();

            if (token != null && token.EffectiveResult == "untossed")
            {
                token.EffectiveResult = parameters["result"];
                tokenDb.SaveChanges();

                string old_hash    = parameters["path_digest"];
                string new_hash    = CCPHelper.code_to_hash(CCPHelper.VerifyToken_code);
                string path_digest = "OAuth[" + new_hash + "((" + old_hash + "))]";

                string result = token.EffectiveResult + "#" + path_digest;

                return(result);
            }
            return("");
        }