private string RefreshAndGetSecurityTokenInner(bool doFinalTokenValidityCheck)
        {
            // Check again to see if the JWT is still invalid, unless we want to skip that check
            if (!doFinalTokenValidityCheck || !this.securityTokenAdapter.IsValid())
            {
                logger.Info("Refreshing session keys");
                sessionKeySupplier.RefreshKeys();

                if (leafCertificateSupplier != null)
                {
                    try
                    {
                        this.leafCertificateSupplier.Refresh();
                    }
                    catch (Exception e)
                    {
                        throw new OciException($"Failed to refresh the leaf Certificate: ", e);
                    }

                    // When using default purpose (ex, instance principals), the token request should always be signed with the same tenant id as the certificate.
                    // For other purposes, the tenant id can be different.
                    if (this.purpose.Equals(DEFAULT_PURPOSE))
                    {
                        string newTenancyId = AuthUtils.GetTenantIdFromCertificate(this.leafCertificateSupplier.GetCertificateAndKeyPair().Certificate);

                        if (!tenancyId.Equals(newTenancyId))
                        {
                            throw new InvalidDataException("The tenancy id should never be changed in cert file!");
                        }
                    }
                }

                foreach (var supplier in intermediateCertificateSuppliers)
                {
                    try
                    {
                        supplier.Refresh();
                    }
                    catch (Exception e)
                    {
                        throw new OciException($"Failed to refresh the intermediate certificate: ", e);
                    }
                }
                securityTokenAdapter = GetSecurityTokenFromServer();
                return(securityTokenAdapter.SecurityToken);
            }
            return(securityTokenAdapter.SecurityToken);
        }
 public X509FederationClient(
     string federationEndpoint,
     string tenancyId,
     IX509CertificateSupplier leafCertificateSupplier,
     ISessionKeySupplier sessionKeySupplier,
     HashSet <IX509CertificateSupplier> intermediateCertificateSuppliers,
     string purpose)
 {
     this.federationEndpoint               = federationEndpoint;
     this.leafCertificateSupplier          = leafCertificateSupplier ?? throw new NullReferenceException();
     this.sessionKeySupplier               = sessionKeySupplier ?? throw new NullReferenceException();
     this.intermediateCertificateSuppliers = intermediateCertificateSuppliers;
     this.tenancyId            = tenancyId ?? throw new NullReferenceException();
     this.securityTokenAdapter = new SecurityTokenAdapter(null);
     this.purpose = purpose ?? throw new NullReferenceException();
 }