Skip to content

Commit ab2a076

Browse files
committed
Implement IUserSecurityStampStore
1 parent 6bbd082 commit ab2a076

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

src/AspNet.Identity.MongoDB/AspNet.Identity.MongoDB.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<package >
33
<metadata>
44
<id>AspNet.Identity.MongoDB</id>
5-
<version>1.0.1-alpha1</version>
5+
<version>1.0.2-alpha1</version>
66
<authors>Wes McClure</authors>
77
<owners>Wes McClure</owners>
88
<licenseUrl>https://github.com/g0t4/aspnet-identity-mongo/blob/master/LICENSE</licenseUrl>
99
<projectUrl>https://github.com/g0t4/aspnet-identity-mongo</projectUrl>
1010
<iconUrl>https://github.com/g0t4/aspnet-identity-mongo</iconUrl>
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1212
<description>A mongodb provider for the new ASP.NET Identity framework. My aim is to ensure this project is well tested and configurable.</description>
13-
<releaseNotes>Adding IUserLoginStore, IUserRoleStore and IUserPasswordStore interfaces.</releaseNotes>
13+
<releaseNotes>Adding IUserSecurityStampStore interfaces.</releaseNotes>
1414
<copyright>MIT</copyright>
1515
<tags>mongo mongodb aspnet identity</tags>
1616
</metadata>

src/AspNet.Identity.MongoDB/IdentityUser.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public IdentityUser()
2020

2121
public string UserName { get; set; }
2222

23+
public string SecurityStamp { get; set; }
24+
2325
[BsonIgnoreIfNull]
2426
public List<string> Roles { get; set; }
2527

src/AspNet.Identity.MongoDB/UserStore.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using global::MongoDB.Driver.Linq;
99
using Microsoft.AspNet.Identity;
1010

11-
public class UserStore<TUser> : IUserStore<TUser>, IUserPasswordStore<TUser>, IUserRoleStore<TUser>, IUserLoginStore<TUser>
11+
public class UserStore<TUser> : IUserStore<TUser>, IUserPasswordStore<TUser>, IUserRoleStore<TUser>, IUserLoginStore<TUser>, IUserSecurityStampStore<TUser>
1212
where TUser : IdentityUser
1313
{
1414
private readonly IdentityContext _Context;
@@ -113,5 +113,16 @@ public Task<TUser> FindAsync(UserLoginInfo login)
113113
.FirstOrDefault(u => u.Logins
114114
.Any(l => l.LoginProvider == login.LoginProvider && l.ProviderKey == login.ProviderKey)));
115115
}
116+
117+
public Task SetSecurityStampAsync(TUser user, string stamp)
118+
{
119+
user.SecurityStamp = stamp;
120+
return Task.FromResult(0);
121+
}
122+
123+
public Task<string> GetSecurityStampAsync(TUser user)
124+
{
125+
return Task.FromResult(user.SecurityStamp);
126+
}
116127
}
117128
}

src/IntegrationTests/IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<Compile Include="UserLoginStoreTests.cs" />
6565
<Compile Include="UserPasswordStoreTests.cs" />
6666
<Compile Include="UserRoleStoreTests.cs" />
67+
<Compile Include="UserSecurityStampStoreTests.cs" />
6768
<Compile Include="UserStoreTests.cs" />
6869
</ItemGroup>
6970
<ItemGroup>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace IntegrationTests
2+
{
3+
using System;
4+
using System.Linq;
5+
using AspNet.Identity.MongoDB;
6+
using Microsoft.AspNet.Identity;
7+
using NUnit.Framework;
8+
9+
[TestFixture]
10+
public class UserSecurityStampStoreTests : UserIntegrationTestsBase
11+
{
12+
[Test]
13+
public void Create_NewUser_HasSecurityStamp()
14+
{
15+
var manager = GetUserManager();
16+
var user = new IdentityUser {UserName = "bob"};
17+
18+
manager.Create(user);
19+
20+
var savedUser = Users.FindAll().Single();
21+
Expect(savedUser.SecurityStamp, Is.Not.Null);
22+
}
23+
24+
[Test]
25+
public void GetSecurityStamp_NewUser_ReturnsStamp()
26+
{
27+
var manager = GetUserManager();
28+
var user = new IdentityUser {UserName = "bob"};
29+
manager.Create(user);
30+
31+
var stamp = manager.GetSecurityStamp(user.Id);
32+
33+
Expect(stamp, Is.Not.Null);
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)