private static string UrlEncodeSegment(byte[] segment) { return(Base64UrlHelpers.Encode(segment)); }
public ClientCredentialWrapper(ApplicationConfiguration config) { ConfidentialClientApplication.GuardMobileFrameworks(); if (config.ConfidentialClientCredentialCount == 0) { throw new MsalClientException( MsalError.ClientCredentialAuthenticationTypeMustBeDefined, MsalErrorMessage.ClientCredentialAuthenticationTypeMustBeDefined); } if (config.ConfidentialClientCredentialCount > 1) { throw new MsalClientException(MsalError.ClientCredentialAuthenticationTypesAreMutuallyExclusive, MsalErrorMessage.ClientCredentialAuthenticationTypesAreMutuallyExclusive); } if (!string.IsNullOrWhiteSpace(config.ClientSecret)) { AuthenticationType = ConfidentialClientAuthenticationType.ClientSecret; } if (config.ClientCredentialCertificate != null) { if (config.ClaimsToSign != null && config.ClaimsToSign.Any()) { AuthenticationType = ConfidentialClientAuthenticationType.ClientCertificateWithClaims; AppendDefaultClaims = config.MergeWithDefaultClaims; } else { AuthenticationType = ConfidentialClientAuthenticationType.ClientCertificate; } } if (!string.IsNullOrWhiteSpace(config.SignedClientAssertion)) { AuthenticationType = ConfidentialClientAuthenticationType.SignedClientAssertion; } if (config.SignedClientAssertionDelegate != null) { AuthenticationType = ConfidentialClientAuthenticationType.SignedClientAssertionDelegate; } switch (AuthenticationType) { case ConfidentialClientAuthenticationType.ClientCertificate: Certificate = config.ClientCredentialCertificate; break; case ConfidentialClientAuthenticationType.ClientCertificateWithClaims: Certificate = config.ClientCredentialCertificate; ClaimsToSign = config.ClaimsToSign; break; case ConfidentialClientAuthenticationType.ClientSecret: Secret = config.ClientSecret; break; case ConfidentialClientAuthenticationType.SignedClientAssertion: SignedAssertion = config.SignedClientAssertion; break; case ConfidentialClientAuthenticationType.SignedClientAssertionDelegate: SignedAssertionDelegate = config.SignedClientAssertionDelegate; break; default: throw new NotImplementedException(); } if (Certificate != null) { Thumbprint = Base64UrlHelpers.Encode(Certificate.GetCertHash()); } }