예제 #1
0
        private void CmdAuth(string[] args)
        {
            if (args.Length < 1)
            {
                PrintCommandHelp("auth");
                return;
            }
            switch (args[0])
            {
            case "signin":
                bool   interactive        = !HasOpt(args, "-n");
                string manualAccessToken  = GetOpt(args, "--at", null);
                string manualRefreshToken = GetOpt(args, "--rt", null);

                // Both --at and --rt should be present, or neither.
                if ((manualAccessToken == null) ^ (manualRefreshToken == null))
                {
                    // One is present, the other isn't: error.
                    PrintLn("*** The --at and --rt options must be both present, or both absent.");
                    return;
                }

                if (manualAccessToken != null)
                {
                    PrintLn("Attempting auth with given tokens...");
                    PolyApi.Authenticate(manualAccessToken, manualRefreshToken, AuthCallback);
                }
                else
                {
                    PrintLn("Attempting {0} auth...", interactive ? "interactive" : "non-interactive");
                    PolyApi.Authenticate(interactive, AuthCallback);
                }
                break;

            case "signout":
                PolyApi.SignOut();
                userProfileImage.sprite = null;
                userProfileImage.gameObject.SetActive(false);
                PrintLn("Requested sign out.");
                break;

            case "cancel":
                PrintLn("Requesting to cancel auth.");
                PolyApi.CancelAuthentication();
                break;

            case "status":
                PrintLn("authenticated: {0}\nauthenticating: {1}\naccess token: {2}\nrefresh token: {3}",
                        PolyApi.IsAuthenticated, PolyApi.IsAuthenticating, PolyApi.AccessToken, PolyApi.RefreshToken);
                break;

            default:
                PrintCommandHelp("auth");
                break;
            }
        }
예제 #2
0
 /// <summary>
 /// Because Poly doesn't live in the Editor/ space (and couldn't, since it uses GameObjects and
 /// MonoBehaviours), it will die every time the user enters or exits play mode. This means
 /// that all of its state and objects will get wiped. So we have to check if it needs initialization
 /// every time we need to use it.
 /// </summary>
 public void EnsurePolyIsReady()
 {
     if (!PolyApi.IsInitialized)
     {
         PtDebug.Log("ABM: Initializing Poly.");
         // We need to set a service name for our auth config because we want to keep our auth credentials
         // separate in a different "silo", so they don't get confused with the runtime credentials
         // the user might be using in their project. Regular users would not set a service name, so they
         // use the default silo.
         authConfig.serviceName = "PolyToolkitEditor";
         PolyApi.Init(authConfig, cacheConfig);
         waitingForSilentAuth = true;
         PolyApi.Authenticate(interactive: false, callback: (PolyStatus status) => {
             waitingForSilentAuth = false;
             OnSignInFinished(/* wasInteractive */ false, status);
         });
     }
 }
예제 #3
0
 /// <summary>
 /// Launches the interactive sign-in flow (launches a browser to perform sign-in).
 /// </summary>
 public void LaunchSignInFlow()
 {
     PolyApi.Authenticate(interactive: true, callback: (PolyStatus status) => {
         OnSignInFinished(/* wasInteractive */ true, status);
     });
 }