Skip to content

Commit 6391352

Browse files
committed
removed namespaces, changed db to use scope and not string
1 parent 6f52b6d commit 6391352

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
using Our.Umbraco.AuthU.Interfaces;
22
using Our.Umbraco.AuthU.Models;
3-
using NPoco;
3+
using Umbraco.Core.Scoping;
44

55
namespace Our.Umbraco.AuthU.Data
66
{
77
public class UmbracoDbOAuthClientStore : IOAuthClientStore
88
{
9-
protected Database Db => new Database("umbracoDbDsn");
9+
private readonly IScopeProvider _scopeProvider;
10+
11+
public UmbracoDbOAuthClientStore(IScopeProvider scopeProvider)
12+
{
13+
_scopeProvider = scopeProvider;
14+
}
1015

1116
public OAuthClient FindClient(string clientId)
1217
{
13-
return Db.SingleOrDefault<OAuthClient>("SELECT * FROM [OAuthClient] WHERE [ClientId] = @0", clientId);
18+
using (var scope = _scopeProvider.CreateScope(autoComplete: true))
19+
{
20+
return scope.Database.SingleOrDefault<OAuthClient>("SELECT * FROM [OAuthClient] WHERE [ClientId] = @0", clientId);
21+
}
1422
}
1523
}
1624
}
Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,50 @@
11
using Our.Umbraco.AuthU.Interfaces;
22
using Our.Umbraco.AuthU.Models;
3-
using NPoco;
3+
using Umbraco.Core.Scoping;
44

55
namespace Our.Umbraco.AuthU.Data
66
{
77
public class UmbracoDbOAuthRefreshTokenStore : IOAuthRefreshTokenStore
8-
{
9-
internal const string CurrentVersion = "1.0.1";
10-
internal const string SubProductName = "AuthU_UmbracoDbOAuthRefreshTokenStore";
8+
{
9+
internal const string CurrentVersion = "1.0.1";
10+
internal const string SubProductName = "AuthU_UmbracoDbOAuthRefreshTokenStore";
1111

12-
protected Database Db => new Database("umbracoDbDsn");
12+
private readonly IScopeProvider _scopeProvider;
13+
14+
public UmbracoDbOAuthRefreshTokenStore(IScopeProvider scopeProvider)
15+
{
16+
_scopeProvider = scopeProvider;
17+
}
1318

1419
public void AddRefreshToken(OAuthRefreshToken token)
1520
{
16-
Db.Execute("DELETE FROM [OAuthRefreshToken] WHERE [Subject] = @0 AND [UserType] = @1 AND [Realm] = @2 AND [ClientId] = @3 AND [DeviceId] = @4",
21+
using (var scope = _scopeProvider.CreateScope(autoComplete: true))
22+
{
23+
scope.Database.Execute("DELETE FROM [OAuthRefreshToken] WHERE [Subject] = @0 AND [UserType] = @1 AND [Realm] = @2 AND [ClientId] = @3 AND [DeviceId] = @4",
1724
token.Subject,
1825
token.UserType,
1926
token.Realm,
2027
token.ClientId,
21-
token.DeviceId);
28+
token.DeviceId);
2229

23-
Db.Save(token);
30+
scope.Database.Save(token);
31+
}
2432
}
2533

2634
public void RemoveRefreshToken(string refreshTokenId)
2735
{
28-
Db.Execute("DELETE FROM [OAuthRefreshToken] WHERE [Key] = @0",
29-
refreshTokenId);
36+
using (var scope = _scopeProvider.CreateScope(autoComplete: true))
37+
{
38+
scope.Database.Execute("DELETE FROM [OAuthRefreshToken] WHERE [Key] = @0", refreshTokenId);
39+
}
3040
}
3141

3242
public OAuthRefreshToken FindRefreshToken(string refreshTokenId)
3343
{
34-
return Db.SingleOrDefault<OAuthRefreshToken>("SELECT * FROM [OAuthRefreshToken] WHERE [Key] = @0",
35-
refreshTokenId);
44+
using (var scope = _scopeProvider.CreateScope(autoComplete: true))
45+
{
46+
return scope.Database.SingleOrDefault<OAuthRefreshToken>("SELECT * FROM [OAuthRefreshToken] WHERE [Key] = @0", refreshTokenId);
47+
}
3648
}
3749
}
3850
}

src/Our.Umbraco.AuthU/Our.Umbraco.AuthU.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@
254254
<Compile Include="Data\Plans\RemoveOAuthTables.cs" />
255255
<Compile Include="Data\Plans\RegisterOAuthTables.cs" />
256256
<Compile Include="Component\MigrationsRunnerComponent.cs" />
257-
<Compile Include="Data\Migrations\UmbracoDbOAuthClientStore\Add\CreateDemoClient.cs" />
258-
<Compile Include="Data\Migrations\UmbracoDbOAuthClientStore\Add\CreateAuthClientStoreTable.cs" />
257+
<Compile Include="Data\Migrations\UmbracoDbOAuthClientStore\CreateDemoClient.cs" />
258+
<Compile Include="Data\Migrations\UmbracoDbOAuthClientStore\CreateAuthClientStoreTable.cs" />
259259
<Compile Include="Data\Migrations\UmbracoDbOAuthClientStore\Remove\DeleteAuthClientStoreTable.cs" />
260260
<Compile Include="Data\Migrations\UmbracoDbOAuthRefreshTokenStore\Add\CreateAuthRefreshTokenStoreTable.cs" />
261261
<Compile Include="Data\Migrations\UmbracoDbOAuthRefreshTokenStore\Add\AddDeviceIdColumn.cs" />

0 commit comments

Comments
 (0)