Beispiel #1
0
        public void Authorization()
        {
            AuthControl authControl = new AuthControl(applicationContract);

            applicationContract.OpenSpecialWindow(authControl);

            if (authControl.IsCanceled)
            {
                return;
            }

            VkApi vk_api = new VkApi();

            ApiAuthParams authParams = new ApiAuthParams();

            authParams.ApplicationId = Convert.ToUInt64(Properties.Resources.client_id);
            authParams.Login         = authControl.GetLogin();
            authParams.Password      = authControl.GetPassword();
            authParams.Settings      = Settings.Friends | Settings.Photos | Settings.Wall | Settings.Messages | Settings.Groups;

            try
            {
                vk_api.Authorize(authParams);
            }
            catch (VkApiException ex)
            {
                applicationContract.OpenSpecialWindow("Vk Auth Error.");
                return;
            }

            for (int i = 0; i < users_count; i++)
            {
                if (users_api[i].UserId.Equals(vk_api.UserId))
                {
                    applicationContract.OpenSpecialWindow("You already authorized.");
                    return;
                }
            }

            users_api.Add(vk_api);
            users_accounts.Add(vk_api.Account.GetProfileInfo());
            users_count++;
        }
Beispiel #2
0
        public void Authorization()
        {
            SlackHelper slackHelper = new SlackHelper(applicationContract);

            slackHelper.Authorize();

            if (!slackHelper.IsAuthorized)
            {
                applicationContract.OpenSpecialWindow("Slack Auth Error.");
                return;
            }

            foreach (SlackHelper item in users_helpers)
            {
                if (item.User.ID == slackHelper.User.ID)
                {
                    applicationContract.OpenSpecialWindow("You already authorized");
                    return;
                }
            }

            users_helpers.Add(slackHelper);
        }
Beispiel #3
0
        public void Authorize()
        {
            String state = Guid.NewGuid().ToString();

            Dictionary <String, String> auth_parameters = new Dictionary <string, string>();

            auth_parameters["client_id"]    = Properties.Resources.client_id;
            auth_parameters["scope"]        = "files:read,chat:write:user,im:read,users:read,channels:read";
            auth_parameters["redirect_uri"] = Properties.Resources.redirect_uri;
            auth_parameters["state"]        = state;

            Uri auth_uri = GetAuthUri(auth_parameters);

            Dictionary <String, String> codeParams = new Dictionary <string, string>();

            codeParams["code"]  = "";
            codeParams["state"] = "";
            codeParams["error"] = "";

            applicationContract.OpenSpecialWindow(auth_uri, new Uri(Properties.Resources.redirect_uri), codeParams);

            if (codeParams["error"] != "" || codeParams["code"] == "" || codeParams["state"] != state)
            {
                return;
            }

            Dictionary <String, String> parameters = new Dictionary <string, string>();

            parameters["client_id"]     = Properties.Resources.client_id;
            parameters["client_secret"] = Properties.Resources.client_secret;
            parameters["redirect_uri"]  = Properties.Resources.redirect_uri;
            parameters["code"]          = codeParams["code"];

            Uri token_get_uri = GetApiUri("oauth.access", parameters);

            Responses.SlackGetTokenResponse getTokenResponse = JsonConvert.DeserializeObject <Responses.SlackGetTokenResponse>(NetHelper.GetRequest(token_get_uri));

            if (getTokenResponse.Ok)
            {
                IsAuthorized  = true;
                _access_token = getTokenResponse.AccessToken;
                User          = Users_Info(getTokenResponse.UserID).User;
            }
        }