Example #1
0
    // Use this for initialization
    void Start()
    {
        var cell   = new Cell();        //new State (States.cell, KeyCode.Space, cellText);
        var sheet0 = new Sheet0();

        sheet0.AddState(cell);
        var lock0 = new Lock0();

        lock0.AddState(cell);
        var mirror = new Mirror();

        mirror.AddState(cell);
        cell.AddState(sheet0);
        cell.AddState(lock0);
        cell.AddState(mirror);
        currentState = cell;
    }
Example #2
0
        public async Task <ActionResult> ProcessLogin([FromBody] Lock0 lock0)
        {
            var model = new UserData();

            model.gender      = "";
            model.friendCount = "";

            String accessToken       = lock0.accessToken;
            String idTokePayload_sub = lock0.idTokenPayload.sub;

            var    auth0Client = new HttpClient();
            string token       = "";

            //string bodyString = "{\"client_id\":\"" + Auth0_Client_Id + "\",\"client_secret\":\"" +
            string bodyString = "{\"client_id\":\"" + _configuration["Auth0:ClientId"] +
                                "\",\"client_secret\":\"" + _configuration["Auth0:ClientSecret"] +
                                "\",\"audience\":\"" + _configuration["Auth0:Audience"] +
                                "\",\"grant_type\":\"client_credentials\"}";

            var response = await auth0Client.PostAsync("https://roses.auth0.com/oauth/token", new StringContent(bodyString, Encoding.UTF8, "application/json"));

            string email = "";

            if (response.IsSuccessStatusCode)
            {
                var responseString = await response.Content.ReadAsStringAsync();

                var responseJson = JObject.Parse(responseString);
                token = (string)responseJson["access_token"];
            }

            // -- OK now I have a token
            // -- let's call the management API to get the user profile
            string id = lock0.idTokenPayload.sub;
            //-- we'll just work with a generic JObject for simplicity
            JObject profile = await GetAuth0UserProfile(id, token);

            email = (string)profile["email"];

            // -- what kind of user?
            if (lock0.idTokenPayload.sub.StartsWith("auth0"))
            {
                JObject fullContact = await GetFullContactData(email);

                model.friendCount = "0";
                model.gender      = "Unknown";
                try {
                    model.gender = (string)fullContact["gender"];
                }
                catch (Exception e)
                {
                    // -- guess we didn't get anything back
                    System.Console.WriteLine("Err: " + e.Message);
                }
            }
            else if (lock0.idTokenPayload.sub.StartsWith("facebook"))
            {
                // -- we'll just work directly with json vs. create an object, etc.
                // -- future, add try/catch block
                string facebookAccessToken = (string)profile["identities"][0]["access_token"];
                string facebookUserID      = (string)profile["identities"][0]["user_id"];

                JObject facebookData = await GetFacebookData(facebookUserID, facebookAccessToken);

                try {
                    model.gender      = (string)facebookData["gender"];
                    model.friendCount = (string)facebookData["friends"]["summary"]["total_count"];
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("Err: " + e.Message);
                }
            }

            return(await Task <ActionResult> .FromResult(Json(model)));
        }