public void createConnection_getAccessToken3Times_Test()
        {
            this._testStartedAt = DateTime.Now;

            List <ADPAccessToken> generatedTokens = new List <ADPAccessToken>();

            for (int i = 0; i < 3; i++)
            {
                ClientCredentialConnection connection = null;

                using (StreamReader sr = new StreamReader("..\\..\\Content\\config\\default.json"))
                {
                    string clientconfig = sr.ReadToEnd();
                    ClientCredentialConfiguration connectionCfg = JSONUtil.Deserialize <ClientCredentialConfiguration>(clientconfig);
                    connection = (ClientCredentialConnection)ADPApiConnectionFactory.createConnection(connectionCfg);
                }

                connection.connect();
                if (connection.isConnectedIndicator())
                {
                    generatedTokens.Add(connection.accessToken);
                }
            }

            generatedTokens.ForEach(token =>
            {
                Assert.AreEqual("Bearer", token.TokenType);
                Assert.IsTrue(token.ExpiresIn > 0); // Assert it's more than 0 sec.
                Assert.AreEqual("api", token.Scope);
                Assert.IsNotNull(token.ExpiresOn);
                Assert.IsTrue(token.ExpiresOn > this._testStartedAt); // Should expire sometime after this test was executed.
            });
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public RedirectResult Authorize()
        {
            String authorizationurl = null;
            AuthorizationCodeConnection connection = null;

            // get new connection configuration
            // JSON config object placed in Web.config configuration or
            // set individual config object attributes
            String clientconfig = UserInfoDemo.Properties.Settings.Default.AuthorizationCodeConfiguration;

            if (String.IsNullOrEmpty(clientconfig))
            {
                ViewBag.IsError = true;
                ViewBag.Message = "Settings file or default options not available.";
            }
            else
            {
                // Initialize the Connection Configuration Object.
                // specifying the ConnectionConfiguration type will get back the right ConnectionConfiguration type object.
                // AuthorizationCodeConfiguration object is returned
                // JavaScriptSerializer oJS = new JavaScriptSerializer();
                AuthorizationCodeConfiguration connectionCfg = JSONUtil.Deserialize <AuthorizationCodeConfiguration>(clientconfig);

                // create a new connection based on the connection configuration object provided
                connection = (AuthorizationCodeConnection)ADPApiConnectionFactory.createConnection(connectionCfg);

                try
                {
                    // Authorization Code Apps require a user to login to ADP
                    // So obtain the authorization URL to redirect the user's
                    // browser so they can login
                    authorizationurl = connection.getAuthorizationURL();

                    // save connection for later use
                    HttpContext.Session["AuthorizationCodeConnection"] = connection;
                }
                catch (Exception e)
                {
                    ViewBag.isError = true;
                    ViewBag.Message = e.Message;
                }
            }

            return(Redirect(authorizationurl));
        }
示例#3
0
        /// <summary>
        /// Demonstrating ADP Client connection library using a product url to get data
        /// after connecting
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            string configFileName = "default.json";

            if (args.Length > 0)
            {
                configFileName = args[0];
            }
            StreamReader sr           = new StreamReader("..\\..\\Content\\config\\" + configFileName);
            string       clientconfig = sr.ReadToEnd();

            //string clientconfig = ADPClientDemo.Properties.Settings.Default.ClientCredentialConfiguration;
            ADPAccessToken token = null;

            if (String.IsNullOrEmpty(clientconfig))
            {
                Console.WriteLine("Settings file or default options not available.");
            }
            else
            {
                ClientCredentialConfiguration connectionCfg = JSONUtil.Deserialize <ClientCredentialConfiguration>(clientconfig);
                ClientCredentialConnection    connection    = (ClientCredentialConnection)ADPApiConnectionFactory.createConnection(connectionCfg);

                try
                {
                    connection.connect();
                    if (connection.isConnectedIndicator())
                    {
                        token = connection.accessToken;

                        Console.WriteLine("Connected to API end point");
                        Console.WriteLine("Token:  ");
                        Console.WriteLine("         AccessToken: {0} ", token.AccessToken);
                        Console.WriteLine("         TokenType: {0} ", token.TokenType);
                        Console.WriteLine("         ExpiresIn: {0} ", token.ExpiresIn);
                        Console.WriteLine("         Scope: {0} ", token.Scope);
                        Console.WriteLine("         ExpiresOn: {0} ", token.ExpiresOn);

                        // var eventsUrl = "/events/core/v1/consumer-application-subscription-credentials.read";
                        // var eventsBody = "{\"events\": [{}]}";
                        // var eventsResults = connection.postADPEvent(eventsUrl, eventsBody);
                        // Console.WriteLine("\r\nEvents Data: {0} ", eventsResults);

                        // String str = connection.getADPData("/hr/v2/workers?limit=5");
                        // Console.WriteLine("\r\nData: {0} ",str);
                    }
                }
                catch (ADPConnectionException e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                Console.Read();
            }
        }
示例#4
0
        /// <summary>
        /// Demonstrating ADP Client connection library using a product url to get data
        /// after connecting
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // get new connection configuration
            // JSON config object placed in Web.config configuration or
            // set individual config object attributes

            string         clientconfig = ADPClientDemo.Properties.Settings.Default.ClientCredentialConfiguration;
            ADPAccessToken token        = null;

            if (String.IsNullOrEmpty(clientconfig))
            {
                Console.WriteLine("Settings file or default options not available.");
            }
            else
            {
                ClientCredentialConfiguration connectionCfg = JSONUtil.Deserialize <ClientCredentialConfiguration>(clientconfig);
                ClientCredentialConnection    connection    = (ClientCredentialConnection)ADPApiConnectionFactory.createConnection(connectionCfg);

                try
                {
                    connection.connect();
                    if (connection.isConnectedIndicator())
                    {
                        token = connection.accessToken;

                        Console.WriteLine("Connected to API end point");
                        Console.WriteLine("Token:  ");
                        Console.WriteLine("         AccessToken: {0} ", token.AccessToken);
                        Console.WriteLine("         TokenType: {0} ", token.TokenType);
                        Console.WriteLine("         ExpiresIn: {0} ", token.ExpiresIn);
                        Console.WriteLine("         Scope: {0} ", token.Scope);
                        Console.WriteLine("         ExpiresOn: {0} ", token.ExpiresOn);

                        // String str = connection.getADPData("https://iat-api.adp.com/hr/v2/workers?limit=5");
                        // Console.WriteLine("\r\nData: {0} ",str);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                Console.Read();
            }
        }