예제 #1
0
        public static async Task <CgApiUser> GetUserByCredentials(CgApiUser.CgApiOauthCredentials credentials)
        {
            SettingsHolder.get_Settings().set_ENC_AuthToken(credentials.ToString());
            SettingsHolder.get_Settings().SaveSettingsAsync(false).ConfigureAwait(false);
            OAuthRequestInfos oAuthRequestInfos = OAuthData.GetOAuthRequestInfos();

            oAuthRequestInfos.UserKey    = credentials.get_Token();
            oAuthRequestInfos.UserSecret = credentials.get_TokenSecret();
            CgApiGlobalOAuthData.set_OAuthRequestInfos(oAuthRequestInfos);
            if (ObjectHolder.UserNotAuthorizedErrorHandler != null)
            {
                CgApiGlobalOAuthData.get_OAuthRequestInfos().UserNotAuthorizedErrorHandler = ObjectHolder.UserNotAuthorizedErrorHandler;
            }
            if (ObjectHolder.ServiceNotAvailablErrorHandler != null)
            {
                OAuthRequestInfos expr_84 = CgApiGlobalOAuthData.get_OAuthRequestInfos();
                expr_84.ServiceNotAvailablErrorHandler = (JsonOAuthRestClient.OnHttpErrorHandler)Delegate.Combine(expr_84.ServiceNotAvailablErrorHandler, ObjectHolder.ServiceNotAvailablErrorHandler);
            }
            CgApiUser cgApiUser = new CgApiUser(oAuthRequestInfos);
            CgApiUser result;

            try
            {
                await cgApiUser.Fetch();

                new CgApiUserCertificateManager().Fetch(cgApiUser.get_Token(), Constants.get_UserDataPath(), Constants.get_OpenVpnBinPath()).ConfigureAwait(false);
            }
            catch (WebException var_4_13F)
            {
                HelperFunctions.DebugLine("UNKNOWN WEBEXCEPTION IN GetUserByCredentials: " + var_4_13F.Message);
                result = null;
                return(result);
            }
            result = cgApiUser;
            return(result);
        }
예제 #2
0
        public static async Task <CgApiUser> GetNewAutoCreatedUser()
        {
            int       num;
            CgApiUser result;
            CgApiUser cgApiUser;

            if (num > 1)
            {
                if (Theming.CurrentTheme == Theming.Theme.Pro)
                {
                    result = null;
                    return(result);
                }
                cgApiUser = new CgApiUser(OAuthData.GetOAuthRequestInfos());
            }
            try
            {
                TaskAwaiter <CgApiUser.CgApiOauthCredentials> var_4 = cgApiUser.CreateUserAndGetCredentials(OAuthInfos.ClientId, SettingsHolder.get_Settings().get_Language(), null, null).GetAwaiter();
                if (!var_4.IsCompleted)
                {
                    await var_4;
                    TaskAwaiter <CgApiUser.CgApiOauthCredentials> taskAwaiter;
                    var_4       = taskAwaiter;
                    taskAwaiter = default(TaskAwaiter <CgApiUser.CgApiOauthCredentials>);
                }
                CgApiUser.CgApiOauthCredentials arg_D0_0 = var_4.GetResult();
                var_4 = default(TaskAwaiter <CgApiUser.CgApiOauthCredentials>);
                CgApiUser.CgApiOauthCredentials cgApiOauthCredentials = arg_D0_0;
                if (cgApiOauthCredentials == null)
                {
                    result = null;
                    return(result);
                }
                SettingsHolder.get_Settings().set_ENC_AuthToken(cgApiOauthCredentials.ToString());
                SettingsHolder.get_Settings().SaveSettingsAsync(false).ConfigureAwait(false);
                OAuthRequestInfos oAuthRequestInfos = OAuthData.GetOAuthRequestInfos();
                oAuthRequestInfos.UserKey    = cgApiOauthCredentials.get_Token();
                oAuthRequestInfos.UserSecret = cgApiOauthCredentials.get_TokenSecret();
                CgApiGlobalOAuthData.set_OAuthRequestInfos(oAuthRequestInfos);
                cgApiUser = new CgApiUser(oAuthRequestInfos);
                ConfiguredTaskAwaitable <bool> .ConfiguredTaskAwaiter var_5 = cgApiUser.Fetch().ConfigureAwait(false).GetAwaiter();
                if (!var_5.IsCompleted)
                {
                    await var_5;
                    ConfiguredTaskAwaitable <bool> .ConfiguredTaskAwaiter configuredTaskAwaiter;
                    var_5 = configuredTaskAwaiter;
                    configuredTaskAwaiter = default(ConfiguredTaskAwaitable <bool> .ConfiguredTaskAwaiter);
                }
                var_5.GetResult();
                var_5 = default(ConfiguredTaskAwaitable <bool> .ConfiguredTaskAwaiter);
                new CgApiUserCertificateManager().Fetch(cgApiUser.get_Token(), Constants.get_UserDataPath(), Constants.get_OpenVpnBinPath()).ConfigureAwait(false);
                if (ObjectHolder.UserNotAuthorizedErrorHandler != null)
                {
                    CgApiGlobalOAuthData.get_OAuthRequestInfos().UserNotAuthorizedErrorHandler = ObjectHolder.UserNotAuthorizedErrorHandler;
                }
                if (ObjectHolder.ServiceNotAvailablErrorHandler != null)
                {
                    OAuthRequestInfos expr_1CE = CgApiGlobalOAuthData.get_OAuthRequestInfos();
                    expr_1CE.ServiceNotAvailablErrorHandler = (JsonOAuthRestClient.OnHttpErrorHandler)Delegate.Combine(expr_1CE.ServiceNotAvailablErrorHandler, ObjectHolder.ServiceNotAvailablErrorHandler);
                }
            }
            catch (WebException var_7_1EA)
            {
                HelperFunctions.DebugLine("UNKNOWN WEBEXCEPTION IN GetNewAutoCreatedUser: " + var_7_1EA.Message);
                result = null;
                return(result);
            }
            result = cgApiUser;
            return(result);
        }