コード例 #1
0
        private bool SendIdentityProviderToApi(JObject identityProvider)
        {
            BaseRequest baseRequest = FederationLibrary.RequestIdentityProviderClient(this.stsUrl, this.apiUrl, this.clientId, this.clientSecret, new string[2]
            {
                "idmconfigapi.access",
                "idmconfigapi.writeidentityproviders"
            });

            if (baseRequest.tokenResponse == null || baseRequest.tokenResponse.IsError)
            {
                return(false);
            }
            baseRequest.Create(identityProvider);
            baseRequest.ExecuteRequest();
            if (baseRequest.HttpStatusCode == HttpStatusCode.Created)
            {
                BaseRequest.LogInfo("Identity provider created.", ConsoleColor.Green);
                return(true);
            }
            if (baseRequest.HttpStatusCode == HttpStatusCode.NotFound)
            {
                BaseRequest.LogError("Failed to create identity provider. Verify API URL is correct.", ConsoleColor.Red);
            }
            else
            {
                BaseRequest.LogError(string.Format("Failed to create identity provider - {0}: {1}", (object)baseRequest.HttpStatusCode, (object)baseRequest.responsePayload), ConsoleColor.Red);
            }
            return(false);
        }
コード例 #2
0
        public void RunImport(string zipName, string idpClientSecret)
        {
            BaseRequest.LogInfo("Importing data...", ConsoleColor.Magenta);
            bool flag = false;

            try
            {
                this.UnzipFiles(zipName);
                flag = this.SendIdentityProviderToApi(this.CreateIdentityProviderJson(this.ValidateOrCreateClientSecret(idpClientSecret)));
            }
            catch (DirectoryNotFoundException ex)
            {
                BaseRequest.LogError(ex.Message, ConsoleColor.Red);
            }
            catch (Exception ex)
            {
                BaseRequest.LogError(ex.ToString(), ConsoleColor.Red);
            }
            FederationLibrary.DeleteContentDirectory();
            if (flag)
            {
                BaseRequest.LogInfo("Import complete.", ConsoleColor.Magenta);
            }
            else
            {
                BaseRequest.LogError("Import failed.", ConsoleColor.Red);
            }
        }
コード例 #3
0
 public void RunExport(string zipName)
 {
     BaseRequest.LogInfo("Exporting data...", ConsoleColor.Magenta);
     Exporter.MakeContentDirectory();
     try
     {
         if (this.RetrieveAndStoreMetadata() && this.RetrieveAndStoreJwks() && this.RetrieveAndStoreSamlMetadata() && this.RetreiveAndStoreIdentityProviderInformation())
         //if (this.RetrieveAndStoreMetadata() && this.RetrieveAndStoreJwks() && this.RetrieveAndStoreSamlMetadata()) && this.RetreiveAndStoreIdentityProviderInformation())
         {
             Exporter.ZipContentDirectory(zipName);
             FederationLibrary.DeleteContentDirectory();
             BaseRequest.LogInfo("Export complete.", ConsoleColor.Magenta);
             return;
         }
     }
     catch (Exception ex)
     {
         BaseRequest.LogError(ex.ToString(), ConsoleColor.Red);
     }
     FederationLibrary.DeleteContentDirectory();
     BaseRequest.LogError("Export failed.", ConsoleColor.Red);
 }
コード例 #4
0
        private bool RetreiveAndStoreIdentityProviderInformation()
        {
            BaseRequest.verbose = true;

            BaseRequest baseRequest = FederationLibrary.RequestIdentityProviderClient(this.stsUrl, this.apiUrl, this.clientId, this.clientSecret, new string[2]
            {
                "idmconfigapi.access",
                "idmconfigapi.readidentityproviders"
            });


            if (baseRequest.tokenResponse == null || baseRequest.tokenResponse.IsError)
            {
                return(false);
            }
            baseRequest.GetAll((string[])null, (string[])null);
            baseRequest.ExecuteRequest();
            JArray  jarray  = JObject.Parse(baseRequest.responsePayload)["resources"].ToObject <JArray>();
            JObject jobject = (JObject)null;

            foreach (JToken jtoken in jarray)
            {
                jobject = jtoken.ToObject <JObject>();
                if (jobject["AuthenticationMode"].ToString().Equals("local", StringComparison.InvariantCultureIgnoreCase))
                {
                    break;
                }
            }
            Exporter.WriteToFile("identityprovider.json", new JObject()
            {
                {
                    "Name",
                    jobject["Name"]
                }
            }.ToString());
            return(true);
        }