Exemple #1
0
        private static void VkontakteAuthGetProfiles(string access_token, string user_id, string email)
        {
            try
            {
                var request = WebRequest.Create(string.Format("https://api.vk.com/method/getProfiles?uid={0}&access_token={1}",
                                                              user_id,
                                                              access_token));

                request.Method = "GET";

                var response = request.GetResponse();
                if (response != null)
                {
                    var vkontakteUser = JsonConvert.DeserializeObject <VkontakteUserResponse>(
                        (new StreamReader(response.GetResponseStream()).ReadToEnd()));
                    OAuthResponce.AuthOrRegCustomer(new Customer
                    {
                        FirstName       = vkontakteUser.response[0].first_name,
                        LastName        = vkontakteUser.response[0].last_name,
                        EMail           = vkontakteUser.response[0].uid + "@temp.vkontakte",
                        CustomerGroupId = 1,
                        Password        = Guid.NewGuid().ToString()
                    });
                }
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
            }
        }
        private static void OdnoklassnikiGetAndLoginUser(string access_token)
        {
            var sigString = string.Format("application_key={0}method={1}{2}",
                                          SettingsOAuth.OdnoklassnikiPublicApiKey,
                                          "users.getCurrentUser",
                                          GetMd5Hash(MD5.Create(), access_token + SettingsOAuth.OdnoklassnikiSecret));

            var request =
                WebRequest.Create(string.Format("http://api.odnoklassniki.ru/fb.do?method={0}&access_token={1}&application_key={2}&sig={3}",
                                                "users.getCurrentUser",
                                                access_token,
                                                SettingsOAuth.OdnoklassnikiPublicApiKey,
                                                GetMd5Hash(MD5.Create(), sigString).ToLower()));

            request.Method = "GET";

            var response = request.GetResponse();

            using (var responseStream = new StreamReader(response.GetResponseStream()))
            {
                var odnoklassnikiResponse = JsonConvert.DeserializeObject <OdnoklassnikiUser>(responseStream.ReadToEnd());
                OAuthResponce.AuthOrRegCustomer(new Customer
                {
                    FirstName       = odnoklassnikiResponse.first_name,
                    LastName        = odnoklassnikiResponse.last_name,
                    EMail           = odnoklassnikiResponse.uid + "@temp.odnoklassniki",
                    CustomerGroupId = 1,
                    Password        = Guid.NewGuid().ToString()
                });
            }
        }
Exemple #3
0
        public static void ExchangeCodeForAccessToken(string code)
        {
            var data = string.Format(
                "code={0}&client_id={1}&client_secret={2}&redirect_uri={3}&grant_type={4}",
                code,
                SettingsOAuth.GoogleClientId,
                SettingsOAuth.GoogleClientSecret,
                StringHelper.MakeASCIIUrl(SettingsMain.SiteUrl) + "/Login.aspx?auth=google",
                "authorization_code");

            var request = WebRequest.Create("https://accounts.google.com/o/oauth2/token?");

            request.Method = "POST";

            byte[] byteArray = Encoding.UTF8.GetBytes(data);

            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;
            using (Stream dataStream = request.GetRequestStream())
            {
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();
            }

            try
            {
                var response = request.GetResponse();

                var responseResult = JsonConvert.DeserializeObject <GoogleOauthResponseAccessToken>(
                    new StreamReader(response.GetResponseStream()).ReadToEnd());

                var userProfile = GetUserInformation(responseResult.access_token);
                OAuthResponce.AuthOrRegCustomer(new Customer
                {
                    FirstName       = userProfile.name,
                    LastName        = userProfile.family_name,
                    EMail           = userProfile.email,
                    CustomerGroupId = 1,
                    Password        = Guid.NewGuid().ToString()
                });
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
            }
        }
 public static void AuthOrRegCustomer(Customer customer)
 {
     OAuthResponce.AuthOrRegCustomer(customer);
 }