Exemple #1
0
        public async Task <bool> RetrieveAuthenticationFromRedirectAsync(Uri uri)
        {
            bool authenticationFound = false;

            if (string.Equals(uri.Authority, this.RedirectUrl.Authority, StringComparison.OrdinalIgnoreCase) &&
                string.Equals(uri.AbsolutePath, this.RedirectUrl.AbsolutePath, StringComparison.OrdinalIgnoreCase))
            {
                DesignTimeAuthenticationViewModel.CheckAuthenticationErrors(uri);

                string[] parameters = uri.Fragment.TrimStart('#').Split('&');

                this.Authentication.AccessToken  = DesignTimeAuthenticationViewModel.RetrieveParameterValue(parameters, "access_token=");
                this.Authentication.RefreshToken = DesignTimeAuthenticationViewModel.RetrieveParameterValue(parameters, "refresh_token=");
                this.Authentication.InstanceUrl  = DesignTimeAuthenticationViewModel.RetrieveParameterValue(parameters, "instance_url=");

                try
                {
                    string id = DesignTimeAuthenticationViewModel.RetrieveParameterValue(parameters, "id=");
                    await this.RetrieveIdInfoAsync(id);
                }
                catch (Exception)
                {
                    this.Authentication.AccessToken  = null;
                    this.Authentication.RefreshToken = null;
                    this.Authentication.InstanceUrl  = null;

                    throw;
                }

                authenticationFound = true;
            }

            return(authenticationFound);
        }
Exemple #2
0
        private static void CheckAuthenticationErrors(Uri uri)
        {
            string[] parameters = uri.Query.TrimStart('?').Split('&');
            string   error      = DesignTimeAuthenticationViewModel.RetrieveParameterValue(parameters, "error=");

            if (error != null)
            {
                string errorDescription = DesignTimeAuthenticationViewModel.RetrieveParameterValue(parameters, "error_description=");

                // In the unexpected case when there is no error description, use the error code.
                string exceptionMessage = errorDescription == null ? error : errorDescription;

                throw new InvalidOperationException(exceptionMessage);
            }
        }