public override void webExecute()
        {
            bool   isRefreshToken        = false;
            bool   isDevice              = false;
            bool   isExternalSDAuth      = false;
            String clientId              = cgiGet("client_id");
            String clientSecret          = cgiGet("client_secret");
            String grantType             = cgiGet("grant_type");
            String nativeToken           = cgiGet("native_token");
            String nativeVerifier        = cgiGet("native_verifier");
            String avoid_redirect        = cgiGet("avoid_redirect");
            String additional_parameters = cgiGet("additional_parameters");
            String refreshToken          = "";
            String userName              = string.Empty;
            String userPassword          = string.Empty;
            String scope = string.Empty;
            string URL   = string.Empty;
            bool   flag  = false;

            try
            {
                DataStoreUtil.LoadDataStores(context);

                if (grantType.Equals("refresh_token", StringComparison.OrdinalIgnoreCase))
                {
                    refreshToken   = cgiGet("refresh_token");
                    isRefreshToken = true;
                }
                else if (grantType.Equals("device", StringComparison.OrdinalIgnoreCase))
                {
                    isDevice = true;
                }
                else if (!string.IsNullOrEmpty(nativeToken))
                {
                    isExternalSDAuth = true;
                }
                else
                {
                    userName     = cgiGet("username");
                    userPassword = cgiGet("password");
                    scope        = cgiGet("scope");
                }

                OutData  gamout;
                GxResult result;
                if (isRefreshToken)
                {
                    result = GxSecurityProvider.Provider.refreshtoken(context, clientId, clientSecret, refreshToken, out gamout, out flag);
                }
                else if (isDevice)
                {
                    result = GxSecurityProvider.Provider.logindevice(context, clientId, clientSecret, out gamout, out flag);
                }
                else if (isExternalSDAuth)
                {
                    result = GxSecurityProvider.Provider.externalauthenticationfromsdusingtoken(context, grantType, nativeToken, nativeVerifier, clientId, clientSecret, ref scope, additional_parameters, out gamout, out flag);
                }
                else if (String.IsNullOrEmpty(additional_parameters))
                {
                    result = GxSecurityProvider.Provider.oauthauthentication(context, grantType, userName, userPassword, clientId, clientSecret, scope, out gamout, out URL, out flag);
                }
                else
                {
                    result = GxSecurityProvider.Provider.oauthauthentication(context, grantType, userName, userPassword, clientId, clientSecret, scope, additional_parameters, out gamout, out URL, out flag);
                }

                localHttpContext.Response.ContentType = MediaTypesNames.ApplicationJson;
                if (!flag)
                {
                    localHttpContext.Response.StatusCode = 401;
                    if (result != null)
                    {
                        string messagePermission = result.Description;
                        HttpHelper.SetResponseStatusAndJsonError(context.HttpContext, result.Code, messagePermission);
                        if (GXUtil.ContainsNoAsciiCharacter(messagePermission))
                        {
                            messagePermission = string.Format("{0}{1}", GxRestPrefix.ENCODED_PREFIX, Uri.EscapeDataString(messagePermission));
                        }
                        localHttpContext.Response.AddHeader(HttpHeader.AUTHENTICATE_HEADER, HttpHelper.OatuhUnauthorizedHeader(context.GetServerName(), result.Code, messagePermission));
                    }
                }
                else
                {
                    if (!isDevice && !isRefreshToken && (gamout == null || String.IsNullOrEmpty((string)gamout["gxTpr_Access_token"])))
                    {
                        if (string.IsNullOrEmpty(avoid_redirect))
                        {
                            localHttpContext.Response.StatusCode = 303;
                        }
                        else
                        {
                            localHttpContext.Response.StatusCode = 200;
                        }
                        localHttpContext.Response.AddHeader("location", URL);
                        Jayrock.Json.JObject jObj = new Jayrock.Json.JObject();
                        jObj.Put("Location", URL);
                        localHttpContext.Response.Write(jObj.ToString());
                    }
                    else
                    {
                        localHttpContext.Response.StatusCode = 200;
                        localHttpContext.Response.Write(gamout.JsonString);
                    }
                }
                context.CloseConnections();
            }
            catch (Exception e)
            {
                localHttpContext.Response.StatusCode = 404;
                localHttpContext.Response.Write(e.Message);
                GXLogging.Error(log, string.Format("Error in access_token service clientId:{0} clientSecret:{1} grantType:{2} userName:{3} scope:{4}", clientId, clientSecret, grantType, userName, scope), e);
            }
        }
        public override void webExecute()
        {
            try
            {
                if (context.isMultipartRequest())
                {
                    localHttpContext.Response.ContentType = MediaTypesNames.TextPlain;
                    var r         = new List <UploadFile>();
                    var fileCount = localHttpContext.Request.GetFileCount();
                    for (var i = 0; i < fileCount; i++)
                    {
                        var      hpf      = localHttpContext.Request.GetFile(i);
                        string   fileName = string.Empty;
                        string[] files    = hpf.FileName.Split(new char[] { '\\' });
                        if (files.Length > 0)
                        {
                            fileName = files[files.Length - 1];
                        }
                        else
                        {
                            fileName = hpf.FileName;
                        }

                        string ext           = FileUtil.GetFileType(fileName);
                        string savedFileName = FileUtil.getTempFileName(Preferences.getTMP_MEDIA_PATH(), FileUtil.GetFileName(fileName), string.IsNullOrEmpty(ext) ? "tmp" : ext);
                        GxFile gxFile        = new GxFile(Preferences.getTMP_MEDIA_PATH(), savedFileName);

                        gxFile.Create(hpf.InputStream);

                        GXFileWatcher.Instance.AddTemporaryFile(gxFile);

                        r.Add(new UploadFile()
                        {
                            name         = fileName,
                            size         = gxFile.GetLength(),
                            url          = gxFile.GetPath(),
                            type         = context.GetContentType(ext),
                            extension    = ext,
                            thumbnailUrl = gxFile.GetPath(),
                            path         = savedFileName
                        });
                    }
                    UploadFilesResult result = new UploadFilesResult()
                    {
                        files = r
                    };
                    var jsonObj = JSONHelper.Serialize(result);
                    localHttpContext.Response.Write(jsonObj);
                }
                else
                {
                    Stream istream     = localHttpContext.Request.GetInputStream();
                    String contentType = localHttpContext.Request.ContentType;
                    String ext         = context.ExtensionForContentType(contentType);

                    string fileName = FileUtil.getTempFileName(Preferences.getTMP_MEDIA_PATH(), "BLOB", string.IsNullOrEmpty(ext) ? "tmp" : ext);
                    GxFile file     = new GxFile(Preferences.getTMP_MEDIA_PATH(), fileName);
                    file.Create(istream);

                    Jayrock.Json.JObject obj = new Jayrock.Json.JObject();
                    fileName = file.GetURI();

                    String fileGuid  = Guid.NewGuid().ToString("N");
                    String fileToken = GxRestPrefix.UPLOAD_PREFIX + fileGuid;
                    CacheAPI.FilesCache.Set(fileGuid, fileName, GxRestPrefix.UPLOAD_TIMEOUT);
                    obj.Put("object_id", fileToken);
                    localHttpContext.Response.AddHeader("GeneXus-Object-Id", fileToken);
                    localHttpContext.Response.ContentType = MediaTypesNames.ApplicationJson;
                    localHttpContext.Response.StatusCode  = 201;
                    localHttpContext.Response.Write(obj.ToString());
                }
            }
            catch (Exception e)
            {
                SendResponseStatus(500, e.Message);
                HttpHelper.SetResponseStatusAndJsonError(localHttpContext, HttpStatusCode.InternalServerError.ToString(), e.Message);
            }
            finally
            {
                try
                {
                    context.CloseConnections();
                }
                catch
                {
                }
            }
        }