Esempio n. 1
0
 private void ApplyToken(string token)
 {
     if (!string.IsNullOrEmpty(token) && WitAuthUtility.IsServerTokenValid(token))
     {
         RefreshAppData(WitAuthUtility.GetAppId(token), token);
     }
 }
Esempio n. 2
0
        private void RefreshAppData(string appId, string token = "")
        {
            var refreshToken = WitAuthUtility.GetAppServerToken(appId, token);

            if (string.IsNullOrEmpty(refreshToken) &&
                string.IsNullOrEmpty(appId) &&
                !string.IsNullOrEmpty(configuration?.application?.id))
            {
                refreshToken = WitAuthUtility.GetAppServerToken(configuration.application.id,
                                                                WitAuthUtility.ServerToken);
                appId = WitAuthUtility.GetAppId(refreshToken);
                if (string.IsNullOrEmpty(appId))
                {
                    UpdateTokenData(refreshToken, () =>
                    {
                        appId = WitAuthUtility.GetAppId(refreshToken);
                        if (appId == configuration.application.id)
                        {
                            configuration.FetchAppConfigFromServerToken(refreshToken, () =>
                            {
                                currentToken = refreshToken;
                                WitAuthUtility.SetAppServerToken(configuration.application.id, currentToken);
                                EditorUtility.SetDirty(configuration);
                                EditorForegroundRunner.Run(Repaint);
                                appConfigurationFoldout = false;
                            });
                        }
                    });
                    return;
                }

                if (appId == configuration.application.id)
                {
                    refreshToken = WitAuthUtility.ServerToken;
                }
            }

            if (currentToken != refreshToken)
            {
                currentToken = refreshToken;
            }

            configuration.FetchAppConfigFromServerToken(refreshToken, () =>
            {
                currentToken = refreshToken;
                EditorForegroundRunner.Run(Repaint);
                appConfigurationFoldout = false;
            });
        }