public DotNetOpenAuth.Messaging.Bindings.CryptoKey GetKey(string bucket, string handle) { DotNetOpenAuth.Messaging.Bindings.CryptoKey key = null; using (IEntityContext context = DependencyInjection.Get<IEntityContext>()) { using (IOAuth2CryptoKeyRepository repository = DependencyInjection.Get<IOAuth2CryptoKeyRepository>(InjectionParameter.Create("context", context))) { IQueryOver<Entity.OAuth2CryptoKey, Entity.OAuth2CryptoKey> query = repository .Query() .Where(x => x.Bucket == bucket) .Where(x => x.Handle == handle); Entity.OAuth2CryptoKey _key = query.List().SingleOrDefault(); if (_key != null) { key = new DotNetOpenAuth.Messaging.Bindings.CryptoKey(Encoding.Unicode.GetBytes(_key.Secret), new DateTime(_key.ExpiresUtc.Ticks, DateTimeKind.Utc)); } } context.Commit(); } return key; }
public void StoreKey(string bucket, string handle, DotNetOpenAuth.Messaging.Bindings.CryptoKey key) { using (IEntityContext context = DependencyInjection.Get<IEntityContext>()) { using (IOAuth2CryptoKeyRepository repository = DependencyInjection.Get<IOAuth2CryptoKeyRepository>(InjectionParameter.Create("context", context))) { Entity.OAuth2CryptoKey _key = new Entity.OAuth2CryptoKey(); _key.ID = Guid.NewGuid(); _key.Bucket = bucket; _key.Handle = handle; _key.Secret = Encoding.Unicode.GetString(key.Key); _key.ExpiresUtc = key.ExpiresUtc; repository.AddOrUpdate(_key); } context.Commit(); } }
public void RemoveKey(string bucket, string handle) { using (IEntityContext context = DependencyInjection.Get<IEntityContext>()) { using (IOAuth2CryptoKeyRepository repository = DependencyInjection.Get<IOAuth2CryptoKeyRepository>(InjectionParameter.Create("context", context))) { IQueryOver<Entity.OAuth2CryptoKey, Entity.OAuth2CryptoKey> query = repository .Query() .Where(x => x.Bucket == bucket); Entity.OAuth2CryptoKey _key = query.List().SingleOrDefault(); repository.Delete(_key); } context.Commit(); } }
public IEnumerable<KeyValuePair<string, DotNetOpenAuth.Messaging.Bindings.CryptoKey>> GetKeys(string bucket) { IEnumerable<KeyValuePair<string, DotNetOpenAuth.Messaging.Bindings.CryptoKey>> keySet; using (IEntityContext context = DependencyInjection.Get<IEntityContext>()) { using (IOAuth2CryptoKeyRepository repository = DependencyInjection.Get<IOAuth2CryptoKeyRepository>(InjectionParameter.Create("context", context))) { IQueryOver<Entity.OAuth2CryptoKey, Entity.OAuth2CryptoKey> query = repository .Query() .Where(x => x.Bucket == bucket); var set = query.List(); keySet = set.Select(x => new KeyValuePair<string, DotNetOpenAuth.Messaging.Bindings.CryptoKey>(x.Handle, new DotNetOpenAuth.Messaging.Bindings.CryptoKey(Encoding.Unicode.GetBytes(x.Secret), new DateTime(x.ExpiresUtc.Ticks, DateTimeKind.Utc)))).ToList(); } context.Commit(); } return keySet; }