Ejemplo n.º 1
0
        public string CreateJwt <TClaims>(
            SoftwareStatementProfile profile,
            TClaims claims,
            bool useOpenBankingJwtHeaders) where TClaims : class
        {
            profile.ArgNotNull(nameof(profile));
            claims.ArgNotNull(nameof(claims));

            Dictionary <string, object> headers = useOpenBankingJwtHeaders
                ? CreateOpenBankingJwtHeaders(
                signingId: profile.SigningKeyId,
                orgId: profile.SoftwareStatementPayload.OrgId,
                softwareId: profile.SoftwareStatementPayload.SoftwareId)
                : CreateJwtHeaders(profile.SigningKeyId);


            string payloadJson = JsonConvert.SerializeObject(
                value: claims,
                settings: new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            X509Certificate2 privateKey = CertificateFactories.GetCertificate2FromPem(
                privateKey: profile.SigningKey,
                pem: profile.SigningCertificate);
            RSA privateKeyRsa = privateKey.GetRSAPrivateKey();

            string result = JWT.Encode(
                payload: payloadJson,
                key: privateKeyRsa,
                algorithm: JwsAlgorithm.PS256,
                extraHeaders: headers);

            return(result);
        }
Ejemplo n.º 2
0
 public Task <X509Certificate2> GetCertificateAsync(string fileName) =>
 CertificateFactories.GetCertificate2FromPem(fileName).ToTaskResult();