Exemplo n.º 1
0
        public static JObject GetCredentials(string serviceName)
        {
            if (cachedCredentials == null)
            {
                try {
                    using (var reader = new StreamReader(new FileStream(CredentialsFilename, FileMode.Open))) {
                        var text   = reader.ReadToEnd();
                        var parsed = JsonConvert.DeserializeObject <Dictionary <string, JObject> > (text);
                        cachedCredentials = parsed;
                    }
                } catch (Exception) {
                    cachedCredentials = new Dictionary <string, JObject> ();
                }
            }

            if (cachedCredentials.ContainsKey(serviceName))
            {
                return(cachedCredentials [serviceName]);
            }

            // Accredit
            ParseInterface.InitializeParse("RAePvLdkN2IHQNZRckrVXzeshpFZTgYif8qu5zuh", "giWKLzMOZa2nrgBjC9YPRF238CTVTpNsMlsIJkr3");

            string key    = Guid.NewGuid().ToString();
            string secret = Guid.NewGuid().ToString();

            /* Get github OAuth authentication link */
            string oauthLink = GetResponse("https://accredit.parseapp.com/requestCredentials", string.Format("service={0}&key={1}&secret={2}", serviceName, key, secret));

            /* Log in github OAuth */
            System.Diagnostics.Process.Start(oauthLink);

            /* Wait for login confirmation */
            WaitForConfirmation(key);

            /* Request the password */
            var response       = GetResponse("https://accredit.parseapp.com/getCredentials", string.Format("key={0}&secret={1}", key, secret));
            var parsedResponse = JObject.Parse(response);

            cachedCredentials [serviceName] = parsedResponse;

            /* Cache it in the current folder for future use */
            try {
                using (FileStream fileStream = File.Open(CredentialsFilename, FileMode.Create, FileAccess.Write)) {
                    using (var streamWriter = new StreamWriter(fileStream)) {
                        streamWriter.Write(JsonConvert.SerializeObject(cachedCredentials));
                    }
                }
            } catch (Exception) {
                Console.Error.WriteLine("Warning: Failed to save credentials to file {0}", CredentialsFilename);
            }

            ParseInterface.InitializeParseForXamarinPerformance();

            return(parsedResponse);
        }
Exemplo n.º 2
0
        public static bool Initialize()
        {
            try {
                var credentials = Accredit.GetCredentials("benchmarker");

                // Xamarin Performance
                InitializeParseForXamarinPerformance();

                var user = AsyncContext.Run(() => ParseInterface.RunWithRetry(() => ParseUser.LogInAsync(credentials ["username"].ToString(), credentials ["password"].ToString())));
                //Console.WriteLine ("LogInAsync");

                //Console.WriteLine ("User authenticated: " + user.IsAuthenticated);

                var acl = new ParseACL(user);
                acl.PublicReadAccess  = true;
                acl.PublicWriteAccess = false;

                defaultACL = acl;
            } catch (Exception e) {
                Console.Error.WriteLine("Error: Exception when initializing Parse API: {0}", e);
                return(false);
            }
            return(true);
        }