Esempio n. 1
0
 /// <summary>
 /// Used in the bootstrap case scenario.
 /// One instance of <see cref="OioIdwsClient"/> must be created for each user.
 /// </summary>
 public OioIdwsClient(OioIdwsClientSettings settings, SecurityToken bootstrapToken) : this(settings)
 {
     if (bootstrapToken == null)
     {
         throw new ArgumentNullException(nameof(bootstrapToken));
     }
     BootstrapToken = bootstrapToken;
 }
Esempio n. 2
0
        /// <summary>
        /// Used in the signature case scenario
        /// </summary>
        public OioIdwsClient(OioIdwsClientSettings settings)
        {
            Settings = settings;
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (settings.ClientCertificate == null)
            {
                throw new ArgumentNullException(nameof(settings.ClientCertificate));
            }

            if (!settings.ClientCertificate.HasPrivateKey)
            {
                throw new ArgumentException("You must have access to the private key of the ClientCertificate", nameof(settings.ClientCertificate));
            }

            if (settings.SecurityTokenService == null)
            {
                throw new ArgumentNullException(nameof(settings.SecurityTokenService));
            }

            if (settings.SecurityTokenService.Certificate == null)
            {
                throw new ArgumentNullException(nameof(settings.SecurityTokenService.Certificate), "Certificate for the SecurityTokenService must be set");
            }

            var tokenServiceConfiguration = new StsTokenServiceConfiguration
            {
                ClientCertificate      = Settings.ClientCertificate,
                StsCertificate         = Settings.SecurityTokenService.Certificate,
                StsEndpointAddress     = Settings.SecurityTokenService.EndpointAddress.ToString(),
                TokenLifeTimeInMinutes = (int?)Settings.SecurityTokenService.TokenLifeTime.GetValueOrDefault().TotalMinutes,
                SendTimeout            = Settings.SecurityTokenService.SendTimeout,
                WspEndpointId          = Settings.AudienceUri.ToString()
            };

            if (settings.SecurityTokenService.CacheClockSkew.HasValue)
            {
                tokenServiceConfiguration.CacheClockSkew = settings.SecurityTokenService.CacheClockSkew.Value;
            }

            if (settings.SecurityTokenService.UseTokenCache)
            {
                _stsTokenService = new StsTokenServiceCache(tokenServiceConfiguration);
            }
            else
            {
                _stsTokenService = new StsTokenService(tokenServiceConfiguration);
            }

            if (settings.UseTokenCache)
            {
                _accessTokenService = new AccessTokenServiceCache(this);
            }
            else
            {
                _accessTokenService = new AccessTokenService(Settings);
            }
        }