Skip to content

Commit

Permalink
https://docs.microsoft.com/en-us/gaming/playfab/release-notes/#221107
Browse files Browse the repository at this point in the history
  • Loading branch information
PlayFab SDK Team authored and PlayFab SDK Team committed Nov 8, 2022
1 parent 8ffb86e commit 12b38d4
Show file tree
Hide file tree
Showing 48 changed files with 898 additions and 70 deletions.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.Identity.Client;
using PlayFab.PfEditor.EditorModels;
using System;
using System.IdentityModel.Tokens.Jwt;
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -102,7 +105,6 @@ public static void DrawAuthPanels()
{
// login mode, this state either logged out, or did not have auto-login checked.
DrawLogin();

}
else if (activeState == PanelDisplayStates.Register)
{
Expand Down Expand Up @@ -153,13 +155,18 @@ private static void DrawLogin()
activeState = PanelDisplayStates.Register;
}

var buttonWidth = 100;
var buttonWidth = 200;
GUILayout.Space(EditorGUIUtility.currentViewWidth - buttonWidth * 2);

if (GUILayout.Button("LOG IN", PlayFabEditorHelper.uiStyle.GetStyle("Button"), GUILayout.MinHeight(32), GUILayout.MaxWidth(buttonWidth)))
{
OnLoginButtonClicked();
}

if (GUILayout.Button("LOG IN WITH MICROSOFT", PlayFabEditorHelper.uiStyle.GetStyle("Button"), GUILayout.MinHeight(32), GUILayout.MaxWidth(buttonWidth)))
{
OnAADLoginButtonClicked();
}
}
}
}
Expand Down Expand Up @@ -301,6 +308,76 @@ private static void OnLoginButtonClicked()
});
}

private static async void OnAADLoginButtonClicked()
{
string[] scopes = new string[] { PlayFabEditorHelper.ED_EX_AAD_SCOPES };

AuthenticationResult authResult = null;

var app = PublicClientApplicationBuilder.Create(PlayFabEditorHelper.ED_EX_AAD_SIGNIN_CLIENTID)
.WithAuthority($"{PlayFabEditorHelper.AAD_SIGNIN_URL}{PlayFabEditorHelper.ED_EX_AAD_SIGNNIN_TENANT}")
.WithRedirectUri("http://localhost")
.Build();

var accounts = await app.GetAccountsAsync();

var firstAccount = accounts.GetEnumerator().Current;

try
{
// Always first try to acquire a token silently.
authResult = await app.AcquireTokenSilent(scopes, firstAccount).ExecuteAsync();
}
catch (MsalUiRequiredException)
{
try
{
SystemWebViewOptions options = new SystemWebViewOptions();
authResult = await app.AcquireTokenInteractive(scopes).WithSystemWebViewOptions(options).ExecuteAsync();
}
catch (MsalException msalex)
{
Debug.Log($"Error acquiring Token:{System.Environment.NewLine}{msalex}");
}
}
catch (Exception ex)
{
Debug.Log($"Error acquiring token silently:{System.Environment.NewLine}{ex}");
return;
}

if (authResult != null)
{
var tokenHandler = new JwtSecurityTokenHandler();
JwtSecurityToken jwtToken = tokenHandler.ReadJwtToken(authResult.AccessToken);

foreach(var audience in jwtToken.Audiences)
{
if (audience.Contains(PlayFabEditorHelper.ED_EX_AAD_SCOPE))
{
PlayFabEditorPrefsSO.Instance.AadAuthorization = authResult.AccessToken;

PlayFabEditorApi.LoginWithAAD(new LoginWithAADRequest() {
DeveloperToolProductName = PlayFabEditorHelper.EDEX_NAME,
DeveloperToolProductVersion = PlayFabEditorHelper.EDEX_VERSION
}, (result) =>
{
PlayFabEditorPrefsSO.Instance.DevAccountToken = result.DeveloperClientToken;
PlayFabEditorDataService.RefreshStudiosList();
PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnLogin);
PlayFabEditorPrefsSO.Save();
PlayFabEditorMenu._menuState = PlayFabEditorMenu.MenuStates.Sdks;
}, PlayFabEditorHelper.SharedErrorCallback);
}
else
{
Debug.Log($"Token acquired but for wrong audience: {audience}");
}
}
}
}

private static void OnContinueButtonClicked()
{
PlayFabEditorApi.Login(new LoginRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public static void Login(LoginRequest request, Action<LoginResult> resultCallbac
PlayFabEditorHttp.MakeApiCall("/DeveloperTools/User/Login", PlayFabEditorHelper.DEV_API_ENDPOINT, request, resultCallback, errorCb);
}

public static void LoginWithAAD(LoginWithAADRequest request, Action<LoginResult> resultCallback, Action<EditorModels.PlayFabError> errorCb)
{
PlayFabEditorHttp.MakeApiCall("/DeveloperTools/User/LoginWithAAD", PlayFabEditorHelper.DEV_API_ENDPOINT, request, resultCallback, errorCb);
}

public static void Logout(LogoutRequest request, Action<LogoutResult> resultCallback,
Action<EditorModels.PlayFabError> errorCb)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ internal static void MakeApiCall<TRequestType, TResultType>(string api, string a
headers.Add("X-SecretKey", PlayFabEditorDataService.ActiveTitle.SecretKey);
}

if(api.Contains("LoginWithAAD"))
{
if(PlayFabEditorPrefsSO.Instance.AadAuthorization == "")
{
Debug.Log("You MUST login through AAD first before calling this api");
return;
}

headers.Add("Authorization", "Bearer "+(PlayFabEditorPrefsSO.Instance.AadAuthorization));
}

//Encode Payload
var payload = System.Text.Encoding.UTF8.GetBytes(req.Trim());
#if UNITY_2018_2_OR_NEWER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public class LoginRequest
public string DeveloperToolProductVersion;
}

public class LoginWithAADRequest
{
public string DeveloperToolProductName;
public string DeveloperToolProductVersion;
}

public class LoginResult
{
public string DeveloperClientToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public static partial class PlayFabEditorHelper
public static string EDEX_UPGRADE_PATH = "/Resources/PlayFabUnityEditorExtensions.unitypackage";
public static string EDEX_PACKAGES_PATH = "/Resources/MostRecentPackage.unitypackage";

public static string AAD_SIGNIN_URL = "https://login.microsoftonline.com/";
public static string ED_EX_AAD_SIGNIN_CLIENTID ="2d99511e-13ec-4b59-99c0-9ae8754f84aa";
public static string ED_EX_AAD_SCOPE = "448adbda-b8d8-4f33-a1b0-ac58cf44d4c1";
public static string ED_EX_AAD_SCOPES = ED_EX_AAD_SCOPE + "/plugin";
public static string ED_EX_AAD_SIGNNIN_TENANT = "common";

public static string CLOUDSCRIPT_FILENAME = ".CloudScript.js"; //prefixed with a '.' to exclude this code from Unity's compiler
public static string CLOUDSCRIPT_PATH = EDEX_ROOT + "/Resources/" + CLOUDSCRIPT_FILENAME;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public static void Save()
public string DevAccountEmail;
public string DevAccountToken;

public string AadAuthorization;

public List<Studio> StudioList = null; // Null means not fetched, empty is a possible return result from GetStudios
public string SelectedStudio;

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
namespace PlayFab.PfEditor { public static partial class PlayFabEditorHelper { public static string EDEX_VERSION = "2.153.221024"; } }
namespace PlayFab.PfEditor { public static partial class PlayFabEditorHelper { public static string EDEX_VERSION = "2.154.221107"; } }
Loading

0 comments on commit 12b38d4

Please sign in to comment.