Пример #1
0
        // PUT https://undone-auth.firebaseio.com/AuthorizationCodes.json?access_token=<ACCESS_TOKEN>
        public async Task <HttpResponseMessage> PutAuthorizationCodes(AuthorizationCodes code)
        {
            var client = new HttpClient();

            client.BaseAddress = new Uri(projectUrl);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            var jsonString = JsonConvert.SerializeObject(code);
            var uniqueId   = code.Id.ToString();
            var response   = await client.PutAsync("AuthorizationCodes/" + uniqueId + ".json?access_token=" + accessToken, new StringContent(jsonString, Encoding.UTF8, "application/json"));

            return(response);
        }
Пример #2
0
        public IActionResult Index([Bind("Response_Type,Client_Id,Redirect_Uri,State,Authen_To_System,username,password")] string username, string password, AuthorizationCodeModel authCodeObj)
        {
            try
            {
                IActionResult response = Unauthorized();

                if (ModelState.IsValid)
                {
                    if (username != string.Empty && username != "null" && username != null)
                    {
                        if (password != string.Empty && password != "null" && password != null)
                        {
                            var IsValidated = false;

                            switch (authCodeObj.Authen_To_System.ToLower())
                            {
                            case "mtl-agent":
                                // TODO: TO VALIDATE USERNAME AND PASSWORD AGAINST MTL AGENT SYSTEM
                                break;

                            case "mtl-smileclub":
                                // TODO: TO VALIDATE USERNAME AND PASSWORD AGAINST MTL SMILE CLUB SYSTEM
                                break;

                            case "mtl-employee":
                                // TODO: TO VALIDATE USERNAME AND PASSWORD AGAINST MTL EMPLOYEE SYSTEM
                                IsValidated = true;
                                break;
                            }

                            if (IsValidated)
                            {
                                var code = Guid.NewGuid();

                                var auth = new AuthorizationCodes();
                                auth.Id              = code;
                                auth.AuthenToSystem  = authCodeObj.Authen_To_System;
                                auth.ClientAppId     = authCodeObj.Client_Id;
                                auth.CreatedDateTime = DateTimes.GetCurrentUtcDateTimeInThaiTimeZone(DateTimes.DateTimeFormat.YearMonthDayByDashTHourMinuteSecondByColonZ, DateTimes.LanguageCultureName.ENGLISH_UNITED_STATES, DateTimes.DateTimeUtcOffset.HHMMByColon);
                                var expdt = DateTime.UtcNow.AddSeconds(90);
                                auth.ExpiryDateTime = DateTimes.ConvertToUtcDateTimeInThaiTimeZone(expdt, DateTimes.DateTimeFormat.YearMonthDayByDashTHourMinuteSecondByColonZ, DateTimes.LanguageCultureName.ENGLISH_UNITED_STATES, DateTimes.DateTimeUtcOffset.HHMMByColon);
                                auth.RedirectUri    = authCodeObj.Redirect_Uri;
                                auth.State          = authCodeObj.State;

                                if (authCodeObj.State != string.Empty && authCodeObj.State != "null" && authCodeObj.State != null)
                                {
                                    var resp = _authObj.PutAuthorizationCodes(auth);

                                    response = Redirect(authCodeObj.Redirect_Uri + "?code=" + code + "&state=" + authCodeObj.State);
                                }
                                else
                                {
                                    response = Redirect(authCodeObj.Redirect_Uri + "?code=" + code);
                                }

                                return(response);
                            }
                            else
                            {
                                return(View());
                            }
                        }
                        else
                        {
                            return(View());
                        }
                    }
                    else
                    {
                        return(View());
                    }
                }
                else
                {
                    return(View());
                }
            }
            catch
            {
                return(View());
            }
        }