public virtual async Task <TClient> RegisterClientAsync(string ownerUserName, string name, OAuthGrantType grantType) { Contract.Requires(!string.IsNullOrEmpty(name)); TClient client = new TClient(); client.GrantType = grantType; using (RijndaelManaged cryptoManager = new RijndaelManaged()) { cryptoManager.GenerateKey(); client.Id = BitConverter.ToString(cryptoManager.Key).Replace("-", string.Empty).ToLowerInvariant(); cryptoManager.GenerateKey(); client.Secret = BitConverter.ToString(cryptoManager.Key).Replace("-", string.Empty).ToLowerInvariant(); } client.OwnerUserName = ownerUserName; client.Name = name; client.SecretHash = new PasswordHasher().HashPassword(client.Secret); client.DateAdded = DateTimeOffset.Now; await ClientCollection.InsertOneAsync(client); return(client); }