//Get Photon Token from playfab
    public static void GetPhotonToken()
    {
        var request = new GetPhotonAuthenticationTokenRequest();
        {
            request.PhotonApplicationId = "67a8e458-b05b-463b-9abe-ce766a75b832".Trim();
        }

        PlayFabClientAPI.GetPhotonAuthenticationToken(request, (result) =>
        {
            string photonToken = result.PhotonCustomAuthenticationToken;
            Debug.Log(string.Format("Yay, logged in in session token: {0}", photonToken));
            PhotonNetwork.AuthValues = new AuthenticationValues();
            PhotonNetwork.AuthValues.AuthType = CustomAuthenticationType.Custom;
            PhotonNetwork.AuthValues.AddAuthParameter("username", PlayFabDataStore.playFabId);
            PhotonNetwork.AuthValues.AddAuthParameter("Token", result.PhotonCustomAuthenticationToken);
            PhotonNetwork.AuthValues.UserId = PlayFabDataStore.playFabId;
            PhotonNetwork.ConnectUsingSettings("1.0");
            
            GetCatalogRunes();
            GetCatalogQuests();
            GetCatalogItems();
        }, (error) =>
        {
            PlayFabUserLogin.playfabUserLogin.Authentication(error.ErrorMessage.ToString().ToUpper(), 3);
        });
    }
Пример #2
0
		/// <summary>
		/// Gets a Photon custom authentication token that can be used to securely join the player into a Photon room. See https://playfab.com/using-photon-playfab for more details.
		/// </summary>
        public static async Task<PlayFabResult<GetPhotonAuthenticationTokenResult>> GetPhotonAuthenticationTokenAsync(GetPhotonAuthenticationTokenRequest request)
        {
            if (AuthKey == null) throw new Exception ("Must be logged in to call this method");

            object httpResult = await PlayFabHTTP.DoPost(PlayFabSettings.GetURL() + "/Client/GetPhotonAuthenticationToken", request, "X-Authorization", AuthKey);
            if(httpResult is PlayFabError)
            {
                PlayFabError error = (PlayFabError)httpResult;
                if (PlayFabSettings.GlobalErrorHandler != null)
                    PlayFabSettings.GlobalErrorHandler(error);
                return new PlayFabResult<GetPhotonAuthenticationTokenResult>
                {
                    Error = error,
                };
            }
            string resultRawJson = (string)httpResult;

            var serializer = JsonSerializer.Create(PlayFabSettings.JsonSettings);
            var resultData = serializer.Deserialize<PlayFabJsonSuccess<GetPhotonAuthenticationTokenResult>>(new JsonTextReader(new StringReader(resultRawJson)));
			
			GetPhotonAuthenticationTokenResult result = resultData.data;
			
			
            return new PlayFabResult<GetPhotonAuthenticationTokenResult>
                {
                    Result = result
                };
        }
Пример #3
0
    void GetPhotonAuthenticationToken()
    {

        GetPhotonAuthenticationTokenRequest req = new GetPhotonAuthenticationTokenRequest();
        req.PhotonApplicationId = "244e35d0-57ff-4e29-b492-62a470851a50";//"2ebff324-aec4-4b3f-8621-4ead47c7758c"; 

        PlayFabClientAPI.GetPhotonAuthenticationToken(req, OnPhotonAuthenticationSuccess, OnPlayfabError);

    }
	// callback on successful LoginToPlayFab request 
	void OnLoginSuccess(LoginResult result)
	{
		Debug.Log(result.PlayFabId);
		StartCoroutine(GetUserStats());
		this.playfabId = result.PlayFabId;
		GetPhotonAuthenticationTokenRequest request = new GetPhotonAuthenticationTokenRequest();
		request.PhotonApplicationId = photonComponent.AppId.Trim();
		// get an authentication ticket to pass on to Photon 
		PlayFabClientAPI.GetPhotonAuthenticationToken(request, OnPhotonAuthenticationSuccess, OnPlayFabError);
	}
Пример #5
0
		/// <summary>
		/// Gets a Photon custom authentication token that can be used to securely join the player into a Photon room. See https://playfab.com/using-photon-playfab for more details.
		/// </summary>
		public static void GetPhotonAuthenticationToken(GetPhotonAuthenticationTokenRequest request, GetPhotonAuthenticationTokenCallback resultCallback, ErrorCallback errorCallback)
		{
			if (AuthKey == null) throw new Exception ("Must be logged in to call this method");

			string serializedJSON = JsonConvert.SerializeObject(request, Util.JsonFormatting, Util.JsonSettings);
			Action<string,string> callback = delegate(string responseStr, string errorStr)
			{
				GetPhotonAuthenticationTokenResult result = null;
				PlayFabError error = null;
				ResultContainer<GetPhotonAuthenticationTokenResult>.HandleResults(responseStr, errorStr, out result, out error);
				if(error != null && errorCallback != null)
				{
					errorCallback(error);
				}
				if(result != null)
				{
					
					if(resultCallback != null)
					{
						resultCallback(result);
					}
				}
			};
			PlayFabHTTP.Post(PlayFabSettings.GetURL()+"/Client/GetPhotonAuthenticationToken", serializedJSON, "X-Authorization", AuthKey, callback);
		}
        /// <summary>
        /// Gets a Photon custom authentication token that can be used to securely join the player into a Photon room. See https://api.playfab.com/docs/using-photon-with-playfab/ for more details.
        /// </summary>
        public static void GetPhotonAuthenticationToken(GetPhotonAuthenticationTokenRequest request, ProcessApiCallback<GetPhotonAuthenticationTokenResult> resultCallback, ErrorCallback errorCallback, object customData = null)
        {
            if (_authKey == null) throw new Exception("Must be logged in to call this method");

            string serializedJson = SimpleJson.SerializeObject(request, Util.ApiSerializerStrategy);
            Action<CallRequestContainer> callback = delegate(CallRequestContainer requestContainer)
            {
                ResultContainer<GetPhotonAuthenticationTokenResult>.HandleResults(requestContainer, resultCallback, errorCallback, null);
            };
            PlayFabHTTP.Post("/Client/GetPhotonAuthenticationToken", serializedJson, "X-Authorization", _authKey, callback, request, customData);
        }
    /// <summary>
    /// Callback called when user login completes.
    /// </summary>
    /// <param name="result">Result of user login</param>
    void OnLoginCompleted(LoginResult result)
    {
        playerID = result.PlayFabId;

        PushNotificationsManager.instance.Register();

        this.LoadTitleData();

				GetPhotonAuthenticationTokenRequest tokenrequest = new GetPhotonAuthenticationTokenRequest();
		tokenrequest.PhotonApplicationId = AppId;
		
				PlayFabClientAPI.GetPhotonAuthenticationToken(tokenrequest, OnPhotonAuthenticationSuccess, OnPlayFabError);


        if (result.NewlyCreated)
        {

            Dictionary<string, string> playerData = new Dictionary<string, string>();
            playerData.Add(GameConstants.accountLevelKey, "0");
            playerData.Add(GameConstants.accountExpKey, "0");
            playerData.Add(GameConstants.facebookPictureKey,playerPictureURL);

            UpdateUserDataRequest request = new UpdateUserDataRequest();
            request.Data = playerData;
            request.Permission = UserDataPermission.Public;

            PlayFabClientAPI.UpdateUserData(request, OnAddDataSuccess, OnAddDataError);
        }
        else
        {
            Dictionary<string, string> playerData = new Dictionary<string, string>();
            playerData.Add(GameConstants.facebookPictureKey, playerPictureURL);

            UpdateUserDataRequest request = new UpdateUserDataRequest();
            request.Data = playerData;
            request.Permission = UserDataPermission.Public;

            PlayFabClientAPI.UpdateUserData(request, OnAddDataSuccess, OnAddDataError);
        }
    }
	private void OnPlayFabLoginSuccess (LoginResult result)
	{
		Debug.Log ("PlayFab Login Success");
		playfabUserID = result.PlayFabId;	// record our playfab user ID

		StartCoroutine(CoGetPlayerXP ());	// request the XP for this user

		GetPhotonAuthenticationTokenRequest request = new GetPhotonAuthenticationTokenRequest ();
		request.PhotonApplicationId = PHOTON_APP_ID;
		// get an authentication ticket to pass on to Photon 
		PlayFabClientAPI.GetPhotonAuthenticationToken (request, OnPhotonAuthenticationSuccess, OnPlayFabError);
	}