/// <summary>
        /// This facade method shows how to use the SDK to obtain an oauth token (with some extra details) out of given LoginID/Password/ClientID parameters.
        /// It also shows how you can instantiate service objects for versions 1.0 and 3.0 of Concur Platform API.
        /// </summary>
        /// <param name="loginId">This is the Email/UserName entered by the user when he/she signin at https://developer.concur.com/ </param>
        /// <param name="password">This is the Password used by the user when he/she signin at https://developer.concur.com/ </param>
        /// <param name="clientId">This is the oauth client id (required to identify the application) and needed to generate an oauth token </param>
        /// <returns>OAuthTokenDetail object, which encapsulates details of the oauth token obtained for the current user</returns>
        public static async Task <OAuthTokenDetail> LoginAsync(string loginId, string password, string clientId)
        {
            var authService = new AuthenticationService();
            OAuthTokenDetail oauthDetail = await authService.GetOAuthTokenAsync(loginId, password, clientId);

            serviceV3 = new Concur.Connect.V3.ConnectService(oauthDetail.AccessToken, oauthDetail.InstanceUrl);
            serviceV1 = new Concur.Connect.V1.ConnectService(oauthDetail.AccessToken, oauthDetail.InstanceUrl);
            return(oauthDetail);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Asynchronous handler activated when the user clicks the Login button.
        /// </summary>
        private async void LoginButton_ClickAsync()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                //Get the user oauth token
                OAuthTokenDetail oauthTokenDetail = await ClientLibraryFacade.LoginAsync(
                    LoginIdTextBox.Text,
                    PasswordTextBox.Text,
                    ClientIdTextBox.Text);

                //Get the user company expense configuration needed to submit expense reports.
                var groupConfig = await ClientLibraryFacade.GetGroupConfigurationAsync();

                //Determine the default expense policy out of the expense configuration,
                //so that the default policy will be selected by default on the UI.
                var policies           = groupConfig.Policies;
                int defaultPolicyIndex = -1;
                for (int i = 0; i < policies.Length; i++)
                {
                    if (policies[i].IsDefault.Value)
                    {
                        defaultPolicyIndex = i;
                        break;
                    }
                }

                //Display the list of expense policies obtained from the company configuration
                //and select the default policy
                ExpensePolicyListBox.DisplayMember = "Name";
                ExpensePolicyListBox.Items.AddRange(groupConfig.Policies);
                if (defaultPolicyIndex != -1)
                {
                    ExpensePolicyListBox.SelectedIndex = defaultPolicyIndex;
                }

                //Display the list of allowed payment types obtained from the company configuration.
                PaymentTypeComboBox.DisplayMember = "Name";
                PaymentTypeComboBox.Items.AddRange(groupConfig.PaymentTypes);
                if (groupConfig.PaymentTypes.Length > 0)
                {
                    PaymentTypeComboBox.SelectedIndex = 0;
                }

                //Display the oauth token obtained from the user login.
                OAuthTokenTextBox.Text         = oauthTokenDetail.AccessToken;
                CreateEverythingButton.Enabled = true;
            }
            catch (Exception except)
            {
                DisplayException(except);
            }
            finally {
                this.Cursor = Cursors.Default;
            }
        }