public Task StartAsync(CancellationToken cancellationToken)
        {
            Console.WriteLine("Arkivering Service is starting.");

            Console.WriteLine("Setter opp FIKS integrasjon for fagsystem...");
            Guid   accountId           = Guid.Parse(config["accountId"]);     /* Fiks IO accountId as Guid Banke kommune eByggesak konto*/
            string privateKey          = File.ReadAllText("privkey.pem");;    /* Private key for offentlig nøkkel supplied to Fiks IO account */
            Guid   integrationId       = Guid.Parse(config["integrationId"]); /* Integration id as Guid eByggesak system X */
            string integrationPassword = config["integrationPassword"];       /* Integration password */

            // Fiks IO account configuration
            var account = new KontoConfiguration(
                accountId,
                privateKey);

            // Id and password for integration associated to the Fiks IO account.
            var integration = new IntegrasjonConfiguration(
                integrationId,
                integrationPassword, "ks:fiks");

            // ID-porten machine to machine configuration
            var maskinporten = new MaskinportenClientConfiguration(
                audience: @"https://oidc-ver2.difi.no/idporten-oidc-provider/",           // ID-porten audience path
                tokenEndpoint: @"https://oidc-ver2.difi.no/idporten-oidc-provider/token", // ID-porten token path
                issuer: @"arkitektum_test",                                               // issuer name
                numberOfSecondsLeftBeforeExpire: 10,                                      // The token will be refreshed 10 seconds before it expires
                certificate: GetCertificate(config["ThumbprintIdPortenVirksomhetssertifikat"]));

            // Optional: Use custom api host (i.e. for connecting to test api)
            var api = new ApiConfiguration(
                scheme: "https",
                host: "api.fiks.test.ks.no",
                port: 443);

            // Optional: Use custom amqp host (i.e. for connection to test queue)
            var amqp = new AmqpConfiguration(
                host: "io.fiks.test.ks.no",
                port: 5671);

            // Combine all configurations
            var configuration = new FiksIOConfiguration(account, integration, maskinporten, api, amqp);

            client = new FiksIOClient(configuration); // See setup of configuration below



            client.NewSubscription(OnReceivedMelding);

            Console.WriteLine("Abonnerer på meldinger på konto " + accountId.ToString() + " ...");


            SendInngående();

            SendUtgående();



            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
 public void WorksWithNullApiConfigurationConstructor()
 {
     var result = new FiksIOConfiguration(
         new KontoConfiguration(Guid.NewGuid(), "string"),
         new IntegrasjonConfiguration(Guid.NewGuid(), "password"),
         new MaskinportenClientConfiguration("aud", "tokenedm", "issuer", 100, Mock.Of <X509Certificate2>()),
         null);
 }
Exemplo n.º 3
0
        private void SetupConfiguration()
        {
            var apiConfiguration     = new ApiConfiguration(_scheme, _host, _port);
            var accountConfiguration = new KontoConfiguration(_accountId, "dummyKey");

            _configuration = new FiksIOConfiguration(
                accountConfiguration,
                new IntegrasjonConfiguration(_integrasjonId, _integrasjonPassword),
                new MaskinportenClientConfiguration("audience", "token", "issuer", 1, new X509Certificate2()),
                apiConfiguration: apiConfiguration,
                katalogConfiguration: _katalogConfiguration);
        }
Exemplo n.º 4
0
        internal FiksIOClient(
            FiksIOConfiguration configuration,
            ICatalogHandler catalogHandler         = null,
            IMaskinportenClient maskinportenClient = null,
            ISendHandler sendHandler = null,
            IDokumentlagerHandler dokumentlagerHandler = null,
            IAmqpHandler amqpHandler             = null,
            HttpClient httpClient                = null,
            IPublicKeyProvider publicKeyProvider = null)
        {
            KontoId = configuration.KontoConfiguration.KontoId;

            maskinportenClient = maskinportenClient ?? new MaskinportenClient(configuration.MaskinportenConfiguration, httpClient);

            _catalogHandler = catalogHandler ?? new CatalogHandler(
                configuration.KatalogConfiguration,
                configuration.IntegrasjonConfiguration,
                maskinportenClient,
                httpClient);

            _publicKeyProvider = publicKeyProvider ?? new CatalogPublicKeyProvider(_catalogHandler);

            var asicEncrypter = new AsicEncrypter(new AsiceBuilderFactory(), new EncryptionServiceFactory());

            _sendHandler = sendHandler ??
                           new SendHandler(
                _catalogHandler,
                maskinportenClient,
                configuration.FiksIOSenderConfiguration,
                configuration.IntegrasjonConfiguration,
                httpClient,
                asicEncrypter,
                _publicKeyProvider);

            _dokumentlagerHandler = dokumentlagerHandler ?? new DokumentlagerHandler(
                configuration.DokumentlagerConfiguration,
                configuration.IntegrasjonConfiguration,
                maskinportenClient,
                httpClient: httpClient);

            _amqpHandler = amqpHandler ?? new AmqpHandler(
                maskinportenClient,
                _sendHandler,
                _dokumentlagerHandler,
                configuration.AmqpConfiguration,
                configuration.IntegrasjonConfiguration,
                configuration.KontoConfiguration);
        }
Exemplo n.º 5
0
        public void DefaultConfigurationForProd()
        {
            var integrationId      = Guid.NewGuid();
            var integrationPassord = Guid.NewGuid().ToString();
            var kontoId            = Guid.NewGuid();
            var privatNokkel       = Guid.NewGuid().ToString();
            var issuer             = Guid.NewGuid().ToString();
            var certificat         = new X509Certificate2();

            var config = FiksIOConfiguration.CreateProdConfiguration(
                integrasjonId: integrationId,
                integrasjonPassord: integrationPassord,
                kontoId: kontoId,
                privatNokkel: privatNokkel,
                issuer: issuer,
                certificate: certificat);

            config.IntegrasjonConfiguration.IntegrasjonId.Should().Be(integrationId);
            config.IntegrasjonConfiguration.IntegrasjonPassord.Should().Be(integrationPassord);
            config.AmqpConfiguration.Host.Should().Be("io.fiks.ks.no");
            config.ApiConfiguration.Host.Should().Be("api.fiks.ks.no");
        }
Exemplo n.º 6
0
 public FiksIOClient(FiksIOConfiguration configuration, HttpClient httpClient = null, IPublicKeyProvider publicKeyProvider = null)
     : this(configuration, null, null, null, null, null, httpClient, publicKeyProvider)
 {
 }
Exemplo n.º 7
0
        public static KS.Fiks.IO.Client.FiksIOClient CreateFiksIoClient(AppSettings.AppSettings appSettings)
        {
            Console.WriteLine("Setter opp FIKS integrasjon for arkivsystem...");
            var accountId           = appSettings.FiksIOConfig.FiksIoAccountId;
            var privateKey          = File.ReadAllText(appSettings.FiksIOConfig.FiksIoPrivateKey);
            var integrationId       = appSettings.FiksIOConfig.FiksIoIntegrationId;
            var integrationPassword = appSettings.FiksIOConfig.FiksIoIntegrationPassword;
            var scope         = appSettings.FiksIOConfig.FiksIoIntegrationScope;
            var audience      = appSettings.FiksIOConfig.MaskinPortenAudienceUrl;
            var tokenEndpoint = appSettings.FiksIOConfig.MaskinPortenTokenUrl;
            var issuer        = appSettings.FiksIOConfig.MaskinPortenIssuer;

            var ignoreSSLError = Environment.GetEnvironmentVariable("AMQP_IGNORE_SSL_ERROR");


            // Fiks IO account configuration
            var account = new KontoConfiguration(
                accountId,
                privateKey);

            // Id and password for integration associated to the Fiks IO account.
            var integration = new IntegrasjonConfiguration(
                integrationId,
                integrationPassword, scope);

            // ID-porten machine to machine configuration
            var maskinporten = new MaskinportenClientConfiguration(
                audience: audience,
                tokenEndpoint: tokenEndpoint,
                issuer: issuer,
                numberOfSecondsLeftBeforeExpire: 10,
                certificate: GetCertificate(appSettings));

            // Optional: Use custom api host (i.e. for connecting to test api)
            var api = new ApiConfiguration(
                scheme: appSettings.FiksIOConfig.ApiScheme,
                host: appSettings.FiksIOConfig.ApiHost,
                port: appSettings.FiksIOConfig.ApiPort);

            var sslOption1 = (!string.IsNullOrEmpty(ignoreSSLError) && ignoreSSLError == "true")
                ? new SslOption()
            {
                Enabled    = true,
                ServerName = appSettings.FiksIOConfig.AmqpHost,
                CertificateValidationCallback =
                    (RemoteCertificateValidationCallback)((sender, certificate, chain, errors) => true)
            }
                : null;


            // Optional: Use custom amqp host (i.e. for connection to test queue)
            var amqp = new AmqpConfiguration(
                host: appSettings.FiksIOConfig.AmqpHost, //"io.fiks.test.ks.no",
                port: appSettings.FiksIOConfig.AmqpPort,
                sslOption1);

            // Combine all configurations
            var configuration = new FiksIOConfiguration(account, integration, maskinporten, api, amqp);

            return(new KS.Fiks.IO.Client.FiksIOClient(configuration));
        }
Exemplo n.º 8
0
 public FiksIOClient(FiksIOConfiguration configuration)
     : this(configuration, null, null, null, null, null)
 {
 }
        public Task StartAsync(CancellationToken cancellationToken)
        {
            Console.WriteLine("ePlansak Service is starting.");
            Console.WriteLine("Setter opp FIKS integrasjon for ePlansak...");
            Guid   accountId           = Guid.Parse(config["accountId"]);     /* Fiks IO accountId as Guid Banke kommune digitalt planregister konto*/
            string privateKey          = File.ReadAllText("privkey.pem");;    /* Private key for offentlig nøkkel supplied to Fiks IO account */
            Guid   integrationId       = Guid.Parse(config["integrationId"]); /* Integration id as Guid ePlansak system X */
            string integrationPassword = config["integrationPassword"];       /* Integration password */
            Guid   sendToaccountId     = Guid.Parse(config["sendToAccountId"]);

            // Fiks IO account configuration
            var account = new KontoConfiguration(
                accountId,
                privateKey);

            // Id and password for integration associated to the Fiks IO account.
            var integration = new IntegrasjonConfiguration(
                integrationId,
                integrationPassword, "ks:fiks");

            // ID-porten machine to machine configuration
            var maskinporten = new MaskinportenClientConfiguration(
                audience: @"https://oidc-ver2.difi.no/idporten-oidc-provider/",           // ID-porten audience path
                tokenEndpoint: @"https://oidc-ver2.difi.no/idporten-oidc-provider/token", // ID-porten token path
                issuer: @"arkitektum_test",                                               // issuer name
                numberOfSecondsLeftBeforeExpire: 10,                                      // The token will be refreshed 10 seconds before it expires
                certificate: GetCertificate(config["ThumbprintIdPortenVirksomhetssertifikat"]));

            // Optional: Use custom api host (i.e. for connecting to test api)
            var api = new ApiConfiguration(
                scheme: "https",
                host: "api.fiks.test.ks.no",
                port: 443);

            // Optional: Use custom amqp host (i.e. for connection to test queue)
            var amqp = new AmqpConfiguration(
                host: "io.fiks.test.ks.no",
                port: 5671);

            // Combine all configurations
            var configuration = new FiksIOConfiguration(account, integration, maskinporten, api, amqp);

            client = new FiksIOClient(configuration); // See setup of configuration below

            Guid receiverId = sendToaccountId;        // Receiver id as Guid
            Guid senderId   = accountId;              // Sender id as Guid

            client.NewSubscription(OnReceivedMelding);

            Console.WriteLine("Abonnerer på meldinger på konto " + accountId.ToString() + " ...");

            var messageRequestOpprettePlan = new MeldingRequest(
                mottakerKontoId: receiverId,
                avsenderKontoId: senderId,
                meldingType: "no.geointegrasjon.plan.oppdatering.oppretteplan.v1");                        // Message type as string https://fiks.ks.no/plan.oppretteplanidentinput.v1.schema.json
                                                                                                           //Se oversikt over meldingstyper på https://github.com/ks-no/fiks-io-meldingstype-katalog/tree/test/schema


            string payload = File.ReadAllText("sampleOpprettePlan.json");


            var msg = client.Send(messageRequestOpprettePlan, payload, "meldingOmNyPlan.json").Result;

            Console.WriteLine("Melding " + msg.MeldingId.ToString() + " sendt..." + msg.MeldingType);
            Console.WriteLine(payload);

            //Pause til neste
            Console.WriteLine("Trykke en tast for neste melding");
            Console.ReadKey();
            SendPlanleggingIgangsatt();

            //Pause til neste
            Console.WriteLine("Trykke en tast for neste melding");
            Console.ReadKey();
            SendPlanvedtak();


            return(Task.CompletedTask);
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            // Relative or absolute path to the *.p12-file containing the test certificate used to sign tokens for Maskinporten
            var p12Filename = Environment.GetEnvironmentVariable("P12FILENAME");

            // Password required to use the certificate
            var p12Password = Environment.GetEnvironmentVariable("P12PWD");

            // The issuer as defined in Maskinporten
            var issuer = Environment.GetEnvironmentVariable("MASKINPORTEN_ISSUER");

            // ID-porten machine to machine configuration
            var maskinportenConfig = new MaskinportenClientConfiguration(
                audience: @"https://ver2.maskinporten.no/",           // ID-porten audience path
                tokenEndpoint: @"https://ver2.maskinporten.no/token", // ID-porten token path
                issuer: issuer,                                       // KS issuer name
                numberOfSecondsLeftBeforeExpire: 10,                  // The token will be refreshed 10 seconds before it expires
                certificate: new X509Certificate2(p12Filename, p12Password));

            // accountId as defined in the Fiks Forvaltning Interface
            var fiksIoAccountId = Environment.GetEnvironmentVariable("FIKS_IO_ACCOUNT_ID");
            // private key corresponding to the public key uploaded in the Fiks Forvaltning Interface
            var fiksIoPrivateKeyPath = Environment.GetEnvironmentVariable("FIKS_IO_PRIVATE_KEY_PATH");

            // Fiks IO account configuration
            var kontoConfig = new KontoConfiguration(
                kontoId: Guid.Parse(fiksIoAccountId) /* Fiks IO accountId as Guid */,
                privatNokkel: ReadFromFile(fiksIoPrivateKeyPath) /* Private key in PEM format, paired with the public key supplied to Fiks IO account */);

            // Values generated in Fiks Forvaltning when creating the "Integrasjon"
            var integrasjonId       = Environment.GetEnvironmentVariable("INTEGRASJON_ID");
            var integrasjonPassword = Environment.GetEnvironmentVariable("INTEGRASJON_PWD");

            // Id and password for integration associated to the Fiks IO account.
            var integrasjonConfig = new IntegrasjonConfiguration(
                Guid.Parse(integrasjonId) /* Integration id as Guid */,
                integrasjonPassword /* Integration password */);


            // Optional: Use custom api host (i.e. for connecting to test api)
            var apiConfig = new ApiConfiguration(
                scheme: "https",
                host: "api.fiks.test.ks.no",
                port: 443);

            // Optional: Use custom amqp host (i.e. for connection to test queue)
            var amqpConfig = new AmqpConfiguration(
                host: "io.fiks.test.ks.no",
                port: 5671);

            // Combine all configurations
            var configuration = new FiksIOConfiguration(kontoConfig, integrasjonConfig, maskinportenConfig, apiConfig,
                                                        amqpConfig);

            using (var client = new FiksIOClient(configuration))
            {
                var lookupTask = client.Lookup(new LookupRequest("999999999", "no.ks.fiks.melding", 2));
                lookupTask.Wait(TimeSpan.FromSeconds(30));

                var konto = lookupTask.Result;
            }
        }