question

Amar avatar image
Amar asked

Auto AddMember to a Group using EntityAPI on CloudScript

@Brendan @SethDu @Citrus Yan

Our App users all logged in through Android and iOS device ID, and we do not have them link to social N/W to discover friend.. The only way user-A can invite user-B to join their group is through their phone book, where they send a text message that has a deep-link, which has a play load with their PlayFabID and GroupID (Since User-A does not know User-B's PlayFab ID he cannot use "InviteToGroup" method).. Similar to: https://community.playfab.com/questions/21616/error-code-1089-when-addmembers-request-is-called.html?childToView=21621#answer-21621

Hence we have the User-A send a Text message to User-B, that that the GroupID they are invited. Ideally, now User-B has to apply for "ApplyToGroup" and User-A has to "AcceptGroupApplication". Instead, we want to be able to have User-B, Auto join User_A's group using the "AddMembers" Group API method. https://docs.microsoft.com/en-us/rest/api/playfab/groups/groups/AddMembers?view=playfab-rest

When we try to use that on cloud script we are getting errors, as User-B is not he Administrator of User-A's Group. Hence we would like to be able to Authenticate via EntityID and Secret, and execute "AddMembers" API method and have User-B join User-A's Group, and send them a Notification as well. Seems like there is not enough documentation on how to Login using Entity and Secret on CloudScript? We do not want to share the Secret to the client to be able to do this?

What is the recommend way to get this Auto Join group flow working, with out compromising any security. Is there an example code that you can share that shows how to use secret to login and execute EntityAPI on cloudScript?

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Seth Du avatar image Seth Du ♦ commented ·

By default, Cloud Script holds a title-level entity token and is able to call server API. Would you share the code snippet of Cloud Script function so that we can dig into it? Otherwise, you may also share the title ID along with the specified function name so that we can check in your title game manager.

0 Likes 0 ·

1 Answer

·
JayZuo avatar image
JayZuo answered

In CloudScript, we can use the pre-defined "entity" object to call Group APIs. As Cloud Script is hosted on PlayFab's server which identifies that process as a Title entity (title claimant), there is no need to worry about how to Login using Entity and Secret on CloudScript. We can just using the following code to add User-B to User-A's Group:

handlers.addMember = function (args, context) {
    let group = {
        Id: args.GroupId, // User-A's Group Id
        Type: "group"
    };
 
    // The profile of the entity specified in the 'ExecuteEntityCloudScript' request.
    // Defaults to the authenticated entity in the X-EntityToken header.
    // I'd suppose it's User-B calling this function with using ExecuteEntityCloudScript API, thus the entityProfile is User-B's profile.
    let entityProfile = context.currentEntity; 
    try {
        entity.AddMembers({ Group: group, Members: [entityProfile.Entity] });
    }
    catch (error) {
        log.error(error);
        return false;
    }
    return true;
}
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.