Example #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;
            }
        }