Ejemplo n.º 1
0
 public SqlServerClientStoreSettingsTests()
 {
     _sut = new SqlServerClientStoreSettings {
         ConnectionString           = "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;",
         ClientsTableName           = "signatureclients",
         ClientClaimsTableName      = "signatureclientclaims",
         MigrationsTableName        = "clientmigrations",
         ClientCacheEntryExpiration = TimeSpan.FromMinutes(3)
     };
 }
        public SqlServerClientStore(SqlServerClientStoreSettings settings, ISignatureAlgorithmConverter signatureAlgorithmConverter)
        {
            _settings = settings ?? throw new ArgumentNullException(nameof(settings));
            _signatureAlgorithmConverter = signatureAlgorithmConverter ?? throw new ArgumentNullException(nameof(signatureAlgorithmConverter));

            _getSql = new Lazy <string>(() => {
                var thisNamespace = typeof(SqlServerNonceStore).Namespace;
                using (var stream = typeof(SqlServerNonceStore).Assembly.GetManifestResourceStream($"{thisNamespace}.Scripts.GetClient.sql")) {
                    // ReSharper disable once AssignNullToNotNullAttribute
                    using (var streamReader = new StreamReader(stream)) {
                        var template = streamReader.ReadToEnd();
                        return(template
                               .Replace(ClientsTableNameToken, _settings.ClientsTableName)
                               .Replace(ClientClaimsTableNameToken, _settings.ClientClaimsTableName));
                    }
                }
            });
            _mergeClientSql = new Lazy <string>(() => {
                var thisNamespace = typeof(SqlServerNonceStore).Namespace;
                using (var stream = typeof(SqlServerNonceStore).Assembly.GetManifestResourceStream($"{thisNamespace}.Scripts.MergeClient.sql")) {
                    // ReSharper disable once AssignNullToNotNullAttribute
                    using (var streamReader = new StreamReader(stream)) {
                        var template = streamReader.ReadToEnd();
                        return(template
                               .Replace(ClientsTableNameToken, _settings.ClientsTableName));
                    }
                }
            });
            _deleteClientClaimsSql = new Lazy <string>(() => {
                var thisNamespace = typeof(SqlServerNonceStore).Namespace;
                using (var stream = typeof(SqlServerNonceStore).Assembly.GetManifestResourceStream($"{thisNamespace}.Scripts.DeleteClientClaims.sql")) {
                    // ReSharper disable once AssignNullToNotNullAttribute
                    using (var streamReader = new StreamReader(stream)) {
                        var template = streamReader.ReadToEnd();
                        return(template
                               .Replace(ClientClaimsTableNameToken, _settings.ClientClaimsTableName));
                    }
                }
            });
            _insertClientClaimSql = new Lazy <string>(() => {
                var thisNamespace = typeof(SqlServerNonceStore).Namespace;
                using (var stream = typeof(SqlServerNonceStore).Assembly.GetManifestResourceStream($"{thisNamespace}.Scripts.InsertClientClaim.sql")) {
                    // ReSharper disable once AssignNullToNotNullAttribute
                    using (var streamReader = new StreamReader(stream)) {
                        var template = streamReader.ReadToEnd();
                        return(template
                               .Replace(ClientClaimsTableNameToken, _settings.ClientClaimsTableName));
                    }
                }
            });
        }
        public static IHttpMessageSigningVerificationBuilder UseSqlServerClientStore(this IHttpMessageSigningVerificationBuilder builder, SqlServerClientStoreSettings clientStoreSettings)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (clientStoreSettings == null)
            {
                throw new ArgumentNullException(nameof(clientStoreSettings));
            }

            return(builder.UseSqlServerClientStore(prov => clientStoreSettings));
        }