Exemplo n.º 1
0
        /// <summary>
        /// oxd-local Setup a new Client using the params
        /// </summary>
        /// <param name="host">Oxd Host</param>
        /// <param name="port">Oxd Port</param>
        /// <param name="setupClientParams">Input parameters for Setup Client command</param>
        /// <returns></returns>
        public SetupClientResponse SetupClient(String host, int port, SetupClientParams setupClientParams)
        {
            Logger.Info("Verifying input parameters.");
            if (string.IsNullOrEmpty(host))
            {
                throw new ArgumentNullException("Oxd Host should not be NULL.");
            }

            if (port <= 0)
            {
                throw new ArgumentNullException("Oxd Port should be a valid port number.");
            }

            if (setupClientParams == null)
            {
                throw new ArgumentNullException("The Setup Client command params should not be NULL.");
            }

            if (string.IsNullOrEmpty(setupClientParams.AuthorizationRedirectUri))
            {
                throw new MissingFieldException("Authorization Redirect Uri is required.");
            }

            try
            {
                Logger.Info("Preparing and sending command.");
                setupClientParams.ProgrammingLanguage = "csharp";
                var cmdSetupClient = new Command {
                    CommandType = CommandType.setup_client, CommandParams = setupClientParams
                };
                var    commandClient   = new CommandClient(host, port);
                string commandResponse = commandClient.send(cmdSetupClient);

                var response = JsonConvert.DeserializeObject <SetupClientResponse>(commandResponse);
                Logger.Info(string.Format("Got response status as {0} and Oxd ID is {1}", response.Status, response.Data.OxdId));

                return(response);
            }
            catch (Exception ex)
            {
                Logger.Log(NLog.LogLevel.Error, ex, "Exception when Setting up Client.");
                return(null);
            }
        }
Exemplo n.º 2
0
        public ActionResult SetupClient(OxdModel oxd)
        {
            Loadoxdsettings();
            var setupClientInputParams = new SetupClientParams();
            var registerSiteClient     = new SetupClientClient();

            //prepare input params for Setup client
            setupClientInputParams.AuthorizationRedirectUri = oxd.RedirectUrl;
            setupClientInputParams.OpHost = oxd.OpHost;
            setupClientInputParams.PostLogoutRedirectUri = oxd.PostLogoutRedirectUrl;
            setupClientInputParams.ClientName            = oxd.ClientName;
            setupClientInputParams.Scope      = scope;
            setupClientInputParams.GrantTypes = grant_types;
            // setupClientInputParams.ClientId = oxd.ClientId;
            // setupClientInputParams.ClientSecret = oxd.ClientSecret;

            var setupClientResponse = new SetupClientResponse();

            if (string.IsNullOrEmpty(oxd.OxdId))
            {
                //Setup Client using OXD Local
                if (oxd.ConnectionType == "local")
                {
                    setupClientResponse = registerSiteClient.SetupClient(oxdHost, oxd.OxdPort, setupClientInputParams);
                }


                //Setup Client using OXD Web
                if (oxd.ConnectionType == "web")
                {
                    setupClientResponse = registerSiteClient.SetupClient(oxd.HttpRestUrl, setupClientInputParams);
                }


                SetConfigValues(oxd, setupClientResponse);

                return(Json(new { oxdId = setupClientResponse.Data.OxdId, clientId = setupClientResponse.Data.clientId, clientSecret = setupClientResponse.Data.clientSecret }));
            }
            else
            {
                return(Json(new { oxdId = oxd.OxdId, clientId = clientid, clientSecret = clientsecret }));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// oxd-web Setup a new Client via http using the params
        /// </summary>
        /// <param name="oxdweburl">Oxd to http REST service URL</param>
        /// <param name="setupClientParams">Input parameters for Setup  Client via http</param>
        /// <returns></returns>

        public SetupClientResponse SetupClient(string oxdweburl, SetupClientParams setupClientParams)
        {
            Logger.Info("Verifying input parameters.");
            if (string.IsNullOrEmpty(oxdweburl))
            {
                throw new ArgumentNullException("Oxd Rest Service URL should not be NULL.");
            }
            try
            {
                var cmdSetupClient = new Command {
                    CommandType = RestCommandType.setup_client, CommandParams = setupClientParams
                };
                var    commandClient   = new CommandClient(oxdweburl);
                string commandResponse = commandClient.send(cmdSetupClient);
                var    response        = JsonConvert.DeserializeObject <SetupClientResponse>(commandResponse);
                return(response);
            }
            catch (Exception ex)
            {
                Logger.Log(NLog.LogLevel.Error, ex, "Exception when Setting up Client");
                return(null);
            }
        }