示例#1
0
        public async Task <IActionResult> PostRejectFollow()
        {
            var activityFollow = new ActivityFollow
            {
                type     = "Follow",
                actor    = "https://mastodon.technology/users/testtest",
                apObject = $"https://{_instanceSettings.Domain}/users/afp"
            };

            await _userService.SendRejectFollowAsync(activityFollow, "mastodon.technology");

            return(View("Index"));
        }
示例#2
0
 public async Task ProcessAsync(Follower follower, SyncTwitterUser twitterUser)
 {
     try
     {
         var activityFollowing = new ActivityFollow
         {
             type     = "Follow",
             actor    = follower.ActorId,
             apObject = UrlFactory.GetActorUrl(_instanceSettings.Domain, twitterUser.Acct)
         };
         await _userService.SendRejectFollowAsync(activityFollowing, follower.Host);
     }
     catch (Exception) { }
 }
示例#3
0
        public async Task <IActionResult> Follow()
        {
            var actor          = $"https://{_instanceSettings.Domain}/users/gra";
            var targethost     = "mastodon.technology";
            var followActivity = new ActivityFollow()
            {
                context  = "https://www.w3.org/ns/activitystreams",
                id       = $"https://{_instanceSettings.Domain}/{Guid.NewGuid()}",
                type     = "Follow",
                actor    = actor,
                apObject = $"https://{targethost}/users/testtest"
            };

            await _activityPubService.PostDataAsync(followActivity, targethost, actor);

            return(View("Index"));
        }
示例#4
0
        public async Task <bool> SendRejectFollowAsync(ActivityFollow activity, string followerHost)
        {
            var acceptFollow = new ActivityRejectFollow()
            {
                context  = "https://www.w3.org/ns/activitystreams",
                id       = $"{activity.apObject}#rejects/follows/{Guid.NewGuid()}",
                type     = "Reject",
                actor    = activity.apObject,
                apObject = new ActivityFollow()
                {
                    id       = activity.id,
                    type     = activity.type,
                    actor    = activity.actor,
                    apObject = activity.apObject
                }
            };
            var result = await _activityPubService.PostDataAsync(acceptFollow, followerHost, activity.apObject);

            return(result == HttpStatusCode.Accepted ||
                   result == HttpStatusCode.OK); //TODO: revamp this for better error handling
        }
        public async Task <bool> FollowRequestedAsync(string signature, string method, string path, string queryString, Dictionary <string, string> requestHeaders, ActivityFollow activity, string body)
        {
            // Validate
            var sigValidation = await ValidateSignature(activity.actor, signature, method, path, queryString, requestHeaders, body);

            if (!sigValidation.SignatureIsValidated)
            {
                return(false);
            }

            // Save Follow in DB
            var followerUserName    = sigValidation.User.preferredUsername.ToLowerInvariant();
            var followerHost        = sigValidation.User.url.Replace("https://", string.Empty).Split('/').First();
            var followerInbox       = sigValidation.User.inbox;
            var followerSharedInbox = sigValidation.User?.endpoints?.sharedInbox;
            var twitterUser         = activity.apObject.Split('/').Last().Replace("@", string.Empty);

            // Make sure to only keep routes
            followerInbox       = OnlyKeepRoute(followerInbox, followerHost);
            followerSharedInbox = OnlyKeepRoute(followerSharedInbox, followerHost);

            var user = _twitterUserService.GetUser(twitterUser);

            if (!user.Protected)
            {
                // Execute
                await _processFollowUser.ExecuteAsync(followerUserName, followerHost, twitterUser, followerInbox, followerSharedInbox);

                // Send Accept Activity
                var acceptFollow = new ActivityAcceptFollow()
                {
                    context  = "https://www.w3.org/ns/activitystreams",
                    id       = $"{activity.apObject}#accepts/follows/{Guid.NewGuid()}",
                    type     = "Accept",
                    actor    = activity.apObject,
                    apObject = new ActivityFollow()
                    {
                        id       = activity.id,
                        type     = activity.type,
                        actor    = activity.actor,
                        apObject = activity.apObject
                    }
                };
                var result = await _activityPubService.PostDataAsync(acceptFollow, followerHost, activity.apObject);

                return(result == HttpStatusCode.Accepted || result == HttpStatusCode.OK); //TODO: revamp this for better error handling
            }
            else
            {
                // Send Reject Activity
                var acceptFollow = new ActivityRejectFollow()
                {
                    context  = "https://www.w3.org/ns/activitystreams",
                    id       = $"{activity.apObject}#rejects/follows/{Guid.NewGuid()}",
                    type     = "Reject",
                    actor    = activity.apObject,
                    apObject = new ActivityFollow()
                    {
                        id       = activity.id,
                        type     = activity.type,
                        actor    = activity.actor,
                        apObject = activity.apObject
                    }
                };
                var result = await _activityPubService.PostDataAsync(acceptFollow, followerHost, activity.apObject);

                return(result == HttpStatusCode.Accepted || result == HttpStatusCode.OK); //TODO: revamp this for better error handling
            }
        }
示例#6
0
        public async Task <bool> FollowRequestedAsync(string signature, string method, string path, string queryString, Dictionary <string, string> requestHeaders, ActivityFollow activity, string body)
        {
            // Validate
            var sigValidation = await ValidateSignature(activity.actor, signature, method, path, queryString, requestHeaders, body);

            if (!sigValidation.SignatureIsValidated)
            {
                return(false);
            }

            // Prepare data
            var followerUserName    = sigValidation.User.preferredUsername.ToLowerInvariant().Trim();
            var followerHost        = sigValidation.User.url.Replace("https://", string.Empty).Split('/').First();
            var followerInbox       = sigValidation.User.inbox;
            var followerSharedInbox = sigValidation.User?.endpoints?.sharedInbox;
            var twitterUser         = activity.apObject.Split('/').Last().Replace("@", string.Empty).ToLowerInvariant().Trim();

            // Make sure to only keep routes
            followerInbox       = OnlyKeepRoute(followerInbox, followerHost);
            followerSharedInbox = OnlyKeepRoute(followerSharedInbox, followerHost);

            // Validate Moderation status
            var followerModPolicy = _moderationRepository.GetModerationType(ModerationEntityTypeEnum.Follower);

            if (followerModPolicy != ModerationTypeEnum.None)
            {
                var followerStatus = _moderationRepository.CheckStatus(ModerationEntityTypeEnum.Follower, $"@{followerUserName}@{followerHost}");

                if (followerModPolicy == ModerationTypeEnum.WhiteListing && followerStatus != ModeratedTypeEnum.WhiteListed ||
                    followerModPolicy == ModerationTypeEnum.BlackListing && followerStatus == ModeratedTypeEnum.BlackListed)
                {
                    return(await SendRejectFollowAsync(activity, followerHost));
                }
            }

            // Validate TwitterAccount status
            var twitterAccountModPolicy = _moderationRepository.GetModerationType(ModerationEntityTypeEnum.TwitterAccount);

            if (twitterAccountModPolicy != ModerationTypeEnum.None)
            {
                var twitterUserStatus = _moderationRepository.CheckStatus(ModerationEntityTypeEnum.TwitterAccount, twitterUser);
                if (twitterAccountModPolicy == ModerationTypeEnum.WhiteListing && twitterUserStatus != ModeratedTypeEnum.WhiteListed ||
                    twitterAccountModPolicy == ModerationTypeEnum.BlackListing && twitterUserStatus == ModeratedTypeEnum.BlackListed)
                {
                    return(await SendRejectFollowAsync(activity, followerHost));
                }
            }

            // Validate User Protected
            var user = _twitterUserService.GetUser(twitterUser);

            if (!user.Protected)
            {
                // Execute
                await _processFollowUser.ExecuteAsync(followerUserName, followerHost, twitterUser, followerInbox, followerSharedInbox, activity.actor);

                return(await SendAcceptFollowAsync(activity, followerHost));
            }
            else
            {
                return(await SendRejectFollowAsync(activity, followerHost));
            }
        }