question

dominiquecanzeri avatar image
dominiquecanzeri asked

c# ServerInstanceAPI: what is the purpose of authenticationContext?

hello,

I looked at the c# code on github. it seems that the authenticationContext ctor param is never used.

every request will start with:

var requestContext = request?.AuthenticationContext ?? authenticationContext

but, requestContext will never be used.

request.AuthenticationContext (all of them) are also never used.

I guess it was planned to bind a ServerInstanceAPI to a specific user.

=> I would like that very much.

it would prevent us from having to specify a PlayFabId for every request.

thanks!

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 ·

Which repository are you referring to?

I believe your guess is correct. InstanceAPI is designed for developer-controlled places to handle multiple users' actions.

0 Likes 0 ·

1 Answer

·
dominiquecanzeri avatar image
dominiquecanzeri answered

hello,

I am talking about this repo: https://github.com/PlayFab/CSharpSDK

You say my guess is correct, but my point was that it doesn't work.

I would have expected this to work:

async Task Test(string titleId, string secretKey)
{
    var playerSettings = new PlayFab.PlayFabApiSettings()
    {
        TitleId = titleId,
    };
    var serverSettings = new PlayFab.PlayFabApiSettings()
    {
        TitleId = titleId,
        DeveloperSecretKey = secretKey,
    };


    var client = new PlayFab.PlayFabClientInstanceAPI(playerSettings);
    var loginResult = await client.LoginWithCustomIDAsync(new PlayFab.ClientModels.LoginWithCustomIDRequest() { CustomId = "myemail@mail.com", CreateAccount = true });


    var server = new PlayFab.PlayFabServerInstanceAPI(serverSettings, loginResult.Result.AuthenticationContext); //this server instance is now bound to myemail@mail.com's account
    var getPlayerProfileResult = await server.GetPlayerProfileAsync(new PlayFab.ServerModels.GetPlayerProfileRequest() { /*no need to specify PlayfabId here, since it is implicit*/});
    //error 400: Invalid input parameters (probably missing PlayFabId)
}


create a PlayFabServerInstanceAPI bound to a specific client.

maybe I just misunderstand what the authenticationContext argument does.

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 ·

It is because the request of PlayFab API has nothing to do with AuthenticationContext, there is nothing implicit inside requests (Line 19). In terms of anything that requests are related, please always refer to official API documentation to see the required properties. If you believe it should be a feature request, You may send a thread on Feature Requests forum to improve the SDK.

In the design model of PlayFabInstanceAPI, usually we only keep the instance of it to store a login session and AuthenticationContext is just a place to retrieve this player's session information. Additionally, you can duplicate another instance with AuthenticationContext, for example:

var client2 = new PlayFab.PlayFabClientInstanceAPI(playerSettings,loginResult.Result.AuthenticationContext);
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.