示例#1
0
        public void FollowDeserializationTest()
        {
            var json = "{ \"@context\":\"https://www.w3.org/ns/activitystreams\",\"id\":\"https://mastodon.technology/c94567cf-1fda-42ba-82fc-a0f82f63ccbe\",\"type\":\"Follow\",\"actor\":\"https://mastodon.technology/users/testtest\",\"object\":\"https://4a120ca2680e.ngrok.io/users/manu\"}";

            var data = ApDeserializer.ProcessActivity(json) as ActivityFollow;

            Assert.AreEqual("https://mastodon.technology/c94567cf-1fda-42ba-82fc-a0f82f63ccbe", data.id);
            Assert.AreEqual("Follow", data.type);
            Assert.AreEqual("https://4a120ca2680e.ngrok.io/users/manu", data.apObject);
        }
        public async Task <IActionResult> Inbox()
        {
            var r = Request;

            using (var reader = new StreamReader(Request.Body))
            {
                var body = await reader.ReadToEndAsync();

                //System.IO.File.WriteAllText($@"C:\apdebug\{Guid.NewGuid()}.json", body);

                var activity = ApDeserializer.ProcessActivity(body);
                // Do something
                var signature = r.Headers["Signature"].First();

                switch (activity?.type)
                {
                case "Follow":
                {
                    var succeeded = await _userService.FollowRequestedAsync(signature, r.Method, r.Path,
                                                                            r.QueryString.ToString(), RequestHeaders(r.Headers), activity as ActivityFollow, body);

                    if (succeeded)
                    {
                        return(Accepted());
                    }
                    else
                    {
                        return(Unauthorized());
                    }
                }

                case "Undo":
                    if (activity is ActivityUndoFollow)
                    {
                        var succeeded = await _userService.UndoFollowRequestedAsync(signature, r.Method, r.Path,
                                                                                    r.QueryString.ToString(), RequestHeaders(r.Headers), activity as ActivityUndoFollow, body);

                        if (succeeded)
                        {
                            return(Accepted());
                        }
                        else
                        {
                            return(Unauthorized());
                        }
                    }
                    return(Accepted());

                default:
                    return(Accepted());
                }
            }

            return(Accepted());
        }
示例#3
0
        public void AcceptDeserializationTest()
        {
            var json = "{\"@context\":\"https://www.w3.org/ns/activitystreams\",\"id\":\"https://mamot.fr/users/testtest#accepts/follows/333879\",\"type\":\"Accept\",\"actor\":\"https://mamot.fr/users/testtest\",\"object\":{\"id\":\"https://85da1577f778.ngrok.io/f89dfd87-f5ce-4603-83d9-405c0e229989\",\"type\":\"Follow\",\"actor\":\"https://85da1577f778.ngrok.io/users/gra\",\"object\":\"https://mamot.fr/users/testtest\"}}";


            var data = ApDeserializer.ProcessActivity(json) as ActivityAcceptFollow;

            Assert.AreEqual("https://mamot.fr/users/testtest#accepts/follows/333879", data.id);
            Assert.AreEqual("Accept", data.type);
            Assert.AreEqual("https://mamot.fr/users/testtest", data.actor);
            Assert.AreEqual("https://85da1577f778.ngrok.io/f89dfd87-f5ce-4603-83d9-405c0e229989", data.apObject.id);
            Assert.AreEqual("https://85da1577f778.ngrok.io/users/gra", data.apObject.actor);
            Assert.AreEqual("Follow", data.apObject.type);
            Assert.AreEqual("https://mamot.fr/users/testtest", data.apObject.apObject);
        }