public ActionResult LogIn(string assertion)
        {
            var client = new RestClient()
            {
                Authority = "https://browserid.org"
            };

            var request = new RestRequest
            {
                Path = "/verify",
                Method = WebMethod.Post,
            };

            var audience = new UriBuilder(Request.Url.Scheme, Request.Url.Host, Request.Url.Port).Uri.ToString();
            var postData = string.Format("assertion={0}&audience={1}", assertion, audience);
            request.AddPostContent(Encoding.Default.GetBytes(postData));
            var response = client.Request(request);

            var json = JsonObject.Parse(response.Content);
            if (json["status"].ReadAs<string>() == "okay")
            {
                // This logs the user in if we have an account for that email address,
                // or creates it otherwise
                SessionUser.Current.Email = json["email"].ReadAs<string>();
                var hashedEmail = HashHelper.Hash(SessionUser.Current.Email);
                if (_Client.Get(hashedEmail) == null)
                {
                    _Client.Store(StoreMode.Add, hashedEmail, string.Empty);
                }
                return Json(SessionUser.Current.Email);
            }
            else
            {
                var message = new KeyValuePair<string, JsonValue>("message", "Could not log you in");
                var status = new KeyValuePair<string, JsonValue>("status", false);
                return Json(new JsonObject(message, status));
            }
        }
Пример #2
0
        private void postMessageToTwitter()
        {
            var credentials = new OAuthCredentials
            {
                Type = OAuthType.ProtectedResource,
                SignatureMethod = OAuthSignatureMethod.HmacSha1,
                ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                ConsumerKey = AppSettings.TwitterConsumerKey,
                ConsumerSecret = AppSettings.TwitterConsumerKeySecret,
                Token = this.accessToken,
                TokenSecret = this.accessTokenSecret,
                Version = "1.0"
            };

            var restClient = new RestClient
            {
                Authority = AppSettings.TwitterStatusUpdateUrl,
                HasElevatedPermissions = true,
                Credentials = credentials,
                Method = WebMethod.Post
            };

            restClient.AddHeader("Content-Type", "application/x-www-form-urlencoded");

            var restRequest = new RestRequest
            {
                Path = "1/statuses/update.xml?status=" + this.postMessage
            };

            var ByteData = Encoding.UTF8.GetBytes(this.postMessage);
            restRequest.AddPostContent(ByteData);
            restClient.BeginRequest(restRequest, new RestCallback(postFinished));
        }
Пример #3
0
        public static void Tweet(string tweet)
        {
            var credentials = new OAuthCredentials
            {
                Type = OAuthType.ProtectedResource,
                SignatureMethod = OAuthSignatureMethod.HmacSha1,
                ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                ConsumerKey = TwitterSettings.ConsumerKey,
                ConsumerSecret = TwitterSettings.ConsumerKeySecret,
                Token = IsolatedStorageSettings.ApplicationSettings[TWITTER_ACCESS_TOKEN_KEY].ToString(),     //The request Token
                TokenSecret = IsolatedStorageSettings.ApplicationSettings[TWITTER_ACCESS_SECRET_KEY].ToString(), 
                Version = "1.0"
            };

            var restClient = new RestClient
            {
                Authority = TwitterSettings.StatusUpdateUrl,
                HasElevatedPermissions = true,
                Credentials = credentials,
                Method = WebMethod.Post
            };

            restClient.AddHeader("Content-Type", "application/x-www-form-urlencoded");

            // Create a Rest Request and fire it
            var restRequest = new RestRequest
            {
                Path = "1/statuses/update.xml?status=" +  tweet 
            };

            var ByteData = Encoding.UTF8.GetBytes(tweet);
            restRequest.AddPostContent(ByteData);
            restClient.BeginRequest(restRequest, new RestCallback(TweetCallback));

        }
Пример #4
0
        static void SendRegistrationToServer(IEnumerable<RegistrationInfo> regs)
        {
            // I'm just so sorry about all this crap.
            string separator = "¬";
            string urls = "", tokens = "", names = "", types = "";
            string version = WPVersion == OSVersion.WP8 ? "8" : "7";

            foreach (var reg in regs)
            {
                urls += reg.ChannelUri + separator;
                names += reg.User.ScreenName + separator;
                tokens += Library.Encrypting.EncodeTokens(reg.User.Key, reg.User.Secret) + separator;
                types += reg.Type + separator;
            }

            // Remove last separator
            urls.Substring(0, urls.Length - 1);
            tokens.Substring(0, tokens.Length - 1);
            names.Substring(0, names.Length - 1);
            types.Substring(0, types.Length - 1);

            string postContents = "{\"AccessTokens\" : \"" + tokens + "\",\"PushUris\" : \"" + urls + "\",\"Usernames\" : \"" + names + "\",\"Types\" : \"" + types + "\",\"OSVersion\" : \"" + version + "\"}";

            var request = new RestRequest();
            request.Path = Library.SensitiveData.PushRegisterPostUriFormat;
            request.Method = WebMethod.Post;
            request.AddHeader("Content-Type", "application/json");
            request.AddPostContent(Encoding.UTF8.GetBytes(postContents));

            try
            {
                new RestClient().BeginRequest(request, (req, resp, s) =>
                {
                    ReportRegisterToUser(resp);
                });
            }
            catch (Exception)
            {
            }
        }
Пример #5
0
        public void BeginRequest(string path, IDictionary<string, string> parameters, IDictionary<string, File> files, WebMethod method, RestCallback callback, object userState)
        {
            var request = new RestRequest
            {
                Path = path,
                Method = method
            };

            if (files != null)
            {
                foreach (var f in files)
                    request.AddFile(f.Key, f.Value.FileName, f.Value.FilePath);
            }

            if (Credentials != null)
                request.Credentials = Credentials;

            if (parameters != null)
                foreach (var p in parameters)
                {
                    request.AddParameter(p.Key, p.Value);
                }
#if !SILVERLIGHT

            if (files != null)
                foreach (var f in files)
                {
                    byte[] rawData = System.IO.File.ReadAllBytes(f.Value.FilePath);
                    request.AddPostContent(rawData);
                }
            //request.AddFile(f.Key, f.Value.FileName, f.Value.FilePath, "image/jpeg");
#endif

            Client.BeginRequest(request, (req, res, obj) =>
            {
                if (callback != null)
                    callback(req, res, obj);
            }, userState);
        }