public string Sign(ClientAssertionCertificateWrapper credential, bool sendCertificate)
        {
            // Base64Url encoded header and claims
            string token = Encode(credential, sendCertificate);

            // Length check before sign
            if (MaxTokenLength < token.Length)
            {
                throw new MsalException(MsalError.EncodedTokenTooLong);
            }

            return(string.Concat(token, ".", UrlEncodeSegment(credential.Sign(_cryptographyManager, token))));
        }
        private string Encode(ClientAssertionCertificateWrapper credential, bool sendCertificate)
        {
            // Header segment
            string jsonHeader = EncodeHeaderToJson(credential, sendCertificate);

            string encodedHeader = EncodeSegment(jsonHeader);

            // Payload segment
            string jsonPayload = JsonHelper.SerializeToJson(Payload);

            string encodedPayload = EncodeSegment(jsonPayload);

            return(string.Concat(encodedHeader, ".", encodedPayload));
        }
            public JWTHeaderWithCertificate(ClientAssertionCertificateWrapper credential, bool sendCertificate)
                : base(credential)
            {
                X509CertificateThumbprint      = Credential.Thumbprint;
                X509CertificatePublicCertValue = null;

                if (!sendCertificate)
                {
                    return;
                }

#if NETSTANDARD || NET_CORE
                X509CertificatePublicCertValue = Convert.ToBase64String(credential.Certificate.RawData);
#elif DESKTOP
                X509CertificatePublicCertValue = Convert.ToBase64String(credential.Certificate.GetRawCertData());
#endif
            }
Exemple #4
0
 /// <summary>
 /// Constructor of client (application) credentials from a <see cref="ClientAssertionCertificateWrapper"/>
 /// </summary>
 /// <param name="certificate">contains information about the certificate previously shared with AAD at application
 /// registration to prove the identity of the application (the client) requesting the tokens.</param>
 public ClientCredentialWrapper(ClientAssertionCertificateWrapper certificate)
 {
     ConfidentialClientApplication.GuardMobileFrameworks();
     Certificate = certificate;
 }
        private static string EncodeHeaderToJson(ClientAssertionCertificateWrapper credential, bool sendCertificate)
        {
            JWTHeaderWithCertificate header = new JWTHeaderWithCertificate(credential, sendCertificate);

            return(JsonHelper.SerializeToJson(header));
        }
 public JWTHeader(ClientAssertionCertificateWrapper credential)
 {
     Credential = credential;
 }