question

duartedd avatar image
duartedd asked

openid access token JWT unique

Hello

so I am trying to be able to make it so that IF the player already has an account that it will login to that account (which should work) BUT the problem is when the player does NOT have an account and i want to link the CURRENT CustomID INSTEAD of creating a seperate account when i cal the login openid method,

It created a NEW account instead of linking to the existing player of that customID....that existing customID which i had made the characters on...

So I need to link the OpenID aaccount with the linkopenid method INSTEAD of the login openid method for no accounts exist the problem with THAT is when the account doesnt exist and I try to call the link with the same token i get an error stating that playfab cant reuse the same token right away to link it...I obviously dont want to have to have the user login then -> fail out then tell him to login in again to google just for another access token...and I would rather not have to explain to the player that ---if you dont have an account already choose this button if you do - choose this one....

I cant check for an existing account (there is no get openidaccountsforallplayers to cycle through and even then i would have to pull the JWT decode it then pull the email from that AND that still doesnt explain how i would get it from playfab since im not sure if that is even stored.

any thoughts on this frictionless flow?

thanks!

Daniel

10 |1200

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

Sarah Zhang avatar image
Sarah Zhang answered

Please correct me if I have any misunderstanding about your question. If a player has a corresponding CustomId, it means this player already has a player account. So I’m not very sure what you mean in the first paragraph.

Do you mean you want to log the players in and link the OpenId with their accounts whether they are first-login players or not? And you want to let players only click a “LoginWithOpenIdConnect” button to complete this log-in flow, is it right? If so, you can refer to the following flow.

  1. Log the player in via LoginWithOpenIdConnect API with setting the CreateAccount field as false. If the player login successfully, please finish this flow. If this player login failed, navigate the 2nd step.
  2. Log the player in via LoginWithCustomID API with setting the CreateAccount field as true. If the CustomId hasn’t been linked with an account, a new account would be created and logged in, if the CustomId has already been linked with an account, an existing PlayFab account would be logged in. After the player has been logged in successfully, navigate to the 3rd step.
  3. Link the OpenId with this logged-in account via LinkOpenIdConnect. Finish the flow here.
10 |1200

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

duartedd avatar image
duartedd answered

Hi @Sarah Zhang thanks for the reply!

Ya so I have the player login automatically with device/customid and then they can link the account up to the customid account. The reason being i dont want to call loginwithopenidconnect first is because i dont want to have the player be prompted to login with the external provider each time.

So the flow is :

loginwithcustomid/deviceid ->

prompt if player wants to link up ->

if existing account - needs to login and load that player data,

else if does not exist ->

need to link the Current logged in account(via Device ID/custom ) to the openid account ...

what loginwithopenidconnect does with the true setting is it CREATEs a new account instead and logs in with THAT account... IF i set the force create to false, i can call the linkopenid method BUT the issue there is that playfab doesnt allow me to reuse that JWT token to try again and i dont want to have to ask the player to authenticate with the external provider and then authenticate again just to pull another JWT token to pass to playfab - not a good player experience in that scenario.

The best scenario would be IF openid exists in playfab title -> call loginwithopenid ( set createaccount = false)

else -> call linkopenid

functionality noticed:

linkopenid will link the openid to the CURRENT account

loginwithopenid when createaccount enabled AND no existing account exists will CREATE a whole new account even though the current playfabid account does not have an openid account associated to it.

thanks again for your help!

Daniel

Just trying to get the best flow with openid with comments to help.

//Login wiht openid

    public static void PlayFabLoginWithOpenID( bool createAccount = false, UnityAction errCallback = null)
    {


        var request = new LoginWithOpenIdConnectRequest
        {
            ConnectionId = OpenIDConnect.OpenIDInfo.connectionid,
            TitleId = PlayFabSettings.TitleId,
            IdToken = JWT,
            CreateAccount = createAccount
        };


     //   MenuHandleRequests.RequestLoadingPrompt(PlayFabAPIMethods.GenericLogin);
        PlayFabClientAPI.LoginWithOpenIdConnect(request, OnOpenIDLoginResult, error =>
        {
            if (errCallback != null && error.Error == PlayFabErrorCode.AccountNotFound)
            {

  ////// THIS IS WHERE I COULD CALL THE LINKOPENIDCONNECT 
   /////BUT IT REQUIRES A NEW JWT due to playfab not allowing
  //////// the request due to nonce duplication even though the
   ////////  account didn't exist so no login was actually performed 
             


   errCallback();
                PF_Bridge.RaiseCallbackError("Account not found, please select a login method to continue.", PlayFabAPIMethods.GenericLogin, MessageDisplayStyle.error);
            }
            else
            {
                OnLoginError(error);
            }
        });



///this links deviceid(customid) to the openid after the login
///so if the player did have an account already it will link the currentid so that the next time the device can just login with the proper account

    private static void OnOpenIDLoginResult(PlayFab.ClientModels.LoginResult result) //LoginResult
    {
        MenuPlayerData.PlayerId = result.PlayFabId;
        if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer || Application.isEditor)
        {  
                LinkDeviceId();
              
        }


        PF_Bridge.RaiseCallbackSuccess(string.Empty, PlayFabAPIMethods.GenericLogin, MessageDisplayStyle.none);
        if (OnLoginSuccess != null)
            OnLoginSuccess(string.Format("SUCCESS: {0}", result.SessionTicket), MessageDisplayStyle.error);
    }



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.

Sarah Zhang avatar image Sarah Zhang commented ·

Thanks for replying. We will try to code and do the test for it. I will inform you if we have some progress.

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.