question

Tamas Szucs avatar image
Tamas Szucs asked

InviteToGroup from Azure Functions with meaningful InvitedByEntity

Hi there,

I'm inviting a player to a Group in an Azure Function script. I want to display a notification on the invited player's end, that who invited her. ListMembershipOpportunities gives back a nice object with InvitedByEntity, that would be perfect, but it's just set to the title entity, not a player.

I'm following the samples to set the authentication context in the functions script, it is a TitleAuthenticationContext.

I tried to get an entity token for the player GetEntityToken in the Invite script to set the AuthenticationContext properly, but it did not work, resulted in 401 Unauthorized Errors. I found in the documentation that "the entity must be a relation of the caller", I don't know what it means exactly, so I can't get an entity token to impersonate a player in azure function script?

Any recommendations, how I should call InviteToGroup from a function to result in an invitation with proper InvitedByEntity?

Thanks,

Tamas

CloudScript
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 answered

I don’t completely understand how your code works, but in my testing codes, the InvitedByEntity shows an title_player_account. I assume your InviteToGroup is called by the server, which holds a title-level token so that the InvitedByEntity is title.

var apiSettings = new PlayFabApiSettings () {
    TitleId = context.TitleAuthenticationContext.Id
};

PlayFabAuthenticationContext titlecontext = new PlayFabAuthenticationContext ();
titlecontext.EntityToken = context.TitleAuthenticationContext.EntityToken;

var entityAPI = new PlayFabGroupsInstanceAPI (apiSettings, titlecontext);

var request = new PlayFab.GroupsModels.InviteToGroupRequest {
    Group = new PlayFab.GroupsModels.EntityKey {
    Id = "xxxxxxxx",
    Type = "group"
    },
    // target player
    Entity = new PlayFab.GroupsModels.EntityKey {
    Id = "xxxxxx",
    Type = "title_player_account"
    } 
};

var result = await entityAPI.InviteToGroupAsync (request);

6 comments
10 |1200

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

Tamas Szucs avatar image Tamas Szucs commented ·

Hi,

The scenario you wrote is working when I call the Groups API from my UE4 client directly, however I'm trying to achieve something different, I want my Azure Function to be able to call this Groups API in the player's name.

I'm calling from my UE4 client the PlayFab backend's /CloudScript/ExecuteFunction endpoint. The AuthenticationContext's EntityToken is set to the title_player_account token I got after login, it's correct.

Now when the ExecuteFunction calls my Azure Function, the Token is no longer title_player_account, it's a different one, with title type.

Tamas

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Tamas Szucs commented ·

Can you share some detailed code? Please remeber to hide sensitive personal information.

0 Likes 0 ·
Tamas Szucs avatar image Tamas Szucs Seth Du ♦ commented ·

Hi,

sorry for the late reply, this is my InviteToParty Azure Function, that is called:

https://gist.github.com/tomfurrier/49f30b5628c2ce3d64eca51994f09e48

The problem still, is that the invitedbyentity is the title entity.

0 Likes 0 ·
Show more comments
Seth Du avatar image
Seth Du answered

Get Entity Token API is for login/authentication purpose. According to the description, it seems you want to get Player ID from the title entity, would you please try GetProfile/ GetProfiles API to retrieve the master player account ID(PlayFab ID) from the title player account ID? Feel free to tell us if you have any questions.

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.

Tamas Szucs avatar image Tamas Szucs commented ·

Hi,

Sorry I probably wasn't clear with my description, so here is my scenario in detail:

Player A calls my InviteToParty Azure Cloud Function with Player B's master player account id as argument. This function does some checks, creates a group if it doesnt exist, and calls PlayFabServerAPI.GetUserAccountInfoAsync to retrieve Player B's TitlePlayerAccount.

Then the function invites Player B with the following request:

{
	"AutoAcceptOutstandingApplication": null,
	"Entity": {
		"Id": "Player B title Id",
		"Type": "title_player_account"
	},
	"Group": {
		"Id": "GROUP ID",
		"Type": "group"
	},
	"RoleId": null,
	"AuthenticationContext": {
		"ClientSessionTicket": null,
		"PlayFabId": null,
		"EntityToken": "THIS TOKEN IS SENT TO THE FUNCTION AS AuthenticationContext, and represents the title",
		"EntityId": null,
		"EntityType": null
	}
}

Then, when I call istMembershipOpportunities for Player B, it gives this:

....
"InvitedByEntity": { "Key": { "Id": "TITLEID", "Type": "title" }, "Lineage": {} },
...

So the problem is, the EntityToken, and the InvitedByEntity is the title, not a player who called the Azure Cloud Function and I want to display for Player B as the invitor.

Thanks,

Tamas

0 Likes 0 ·

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.