Skip to content

Commit 599d492

Browse files
Merge pull request #38 from marccameron3d/umb8upgrade
Umbraco 8 Update
2 parents 60287fd + a113857 commit 599d492

30 files changed

+564
-370
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using Umbraco.Core.Logging;
3+
using Umbraco.Core.Migrations;
4+
using Umbraco.Core.Composing;
5+
using Umbraco.Core.Migrations.Upgrade;
6+
using Umbraco.Core.Scoping;
7+
using Umbraco.Core.Services;
8+
using Our.Umbraco.AuthU.Data.Migrations.Plans;
9+
10+
namespace Our.Umbraco.AuthU.Component
11+
{
12+
/// <summary>
13+
/// This creates a component we can register as umbraco 8 starts up
14+
/// This is done in MigrationRunnerComposer.cs
15+
/// </summary>
16+
internal class MigrationsRunnerComponent : IComponent
17+
{
18+
private readonly IScopeProvider _scopeProvider;
19+
private readonly IMigrationBuilder _migrationBuilder;
20+
private readonly IKeyValueService _keyValueService;
21+
private readonly ILogger _logger;
22+
23+
public MigrationsRunnerComponent(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
24+
{
25+
_scopeProvider = scopeProvider;
26+
_migrationBuilder = migrationBuilder;
27+
_keyValueService = keyValueService;
28+
_logger = logger;
29+
}
30+
31+
public void Initialize()
32+
{
33+
try
34+
{
35+
//Create the oAuth tables
36+
var upgrader = new Upgrader(new RegisterOAuthTables());
37+
38+
upgrader.Execute(_scopeProvider, _migrationBuilder, _keyValueService, _logger);
39+
}
40+
catch (Exception e)
41+
{
42+
Current.Logger.Error<MigrationsRunnerComponent>($"Error running Migration Planner migration", e);
43+
}
44+
}
45+
46+
public void Terminate()
47+
{
48+
49+
}
50+
}
51+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Our.Umbraco.AuthU.Component;
2+
using Umbraco.Core;
3+
using Umbraco.Core.Composing;
4+
5+
namespace Our.Umbraco.AuthU.Composer
6+
{
7+
/// <summary>
8+
/// This class registers components at umbraco start up.
9+
/// </summary>
10+
class MigrationRunnerComposer : IUserComposer
11+
{
12+
public void Compose(Composition composition)
13+
{
14+
//Registers the Migrations Runner component, this creates the tables
15+
//required for the oAuth stores.
16+
composition.Components().Append<MigrationsRunnerComponent>();
17+
}
18+
}
19+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Our.Umbraco.AuthU.Models;
2+
using Umbraco.Core.Composing;
3+
4+
namespace Our.Umbraco.AuthU.Data.Helpers
5+
{
6+
/// <summary>
7+
/// This is a helper to retrieve the latest store value, created to allow us to run migrations
8+
/// without storing the key anywhere else.
9+
/// [umbracoKeyValue] - Umbraco.Core.Upgrader.State+AuthU
10+
/// </summary>
11+
public static class AuthUKeyValueHelper
12+
{
13+
public static string GetValue()
14+
{
15+
string authUState = string.Empty;
16+
17+
using (var scope = Current.ScopeProvider.CreateScope())
18+
{
19+
var database = scope.Database;
20+
var existing = database.SingleOrDefault<UmbracoKeyValue>("SELECT * FROM [umbracoKeyValue] WHERE [key] = 'Umbraco.Core.Upgrader.State+AuthU'");
21+
if (existing != null)
22+
{
23+
authUState = existing.Value;
24+
}
25+
scope.Complete();
26+
}
27+
28+
return authUState;
29+
}
30+
}
31+
}

src/Our.Umbraco.AuthU/Data/InMemoryOAuthClientStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public InMemoryOAuthClientStore(IEnumerable<OAuthClient> clients)
1414
{
1515
foreach (var client in clients)
1616
{
17-
client.Secret = client.Secret.GenerateHash();
17+
client.Secret = client.Secret.GenerateOAuthHash();
1818
}
1919

2020
this._clients = clients;

src/Our.Umbraco.AuthU/Data/Migrations/BaseMigration.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/Our.Umbraco.AuthU/Data/Migrations/MigrationsRunner.cs

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/Our.Umbraco.AuthU/Data/Migrations/UmbracoDbOAuthClientStore/1.0.0/CreateDemoClient.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/Our.Umbraco.AuthU/Data/Migrations/UmbracoDbOAuthClientStore/1.0.0/CreateTable.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Our.Umbraco.AuthU.Models;
2+
using Umbraco.Core.Migrations;
3+
4+
namespace Our.Umbraco.AuthU.Data.Migrations.UmbracoDbOAuthClientStore
5+
{
6+
/// <summary>
7+
/// Simple migration to create the OAuthClient Table
8+
/// </summary>
9+
internal class CreateAuthClientStoreTable : MigrationBase
10+
{
11+
public CreateAuthClientStoreTable(IMigrationContext context)
12+
: base(context)
13+
{ }
14+
15+
public override void Migrate()
16+
{
17+
if (!TableExists("OAuthClient"))
18+
Create.Table<OAuthClient>().Do();
19+
}
20+
}
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Our.Umbraco.AuthU.Models;
2+
using Umbraco.Core.Migrations;
3+
4+
namespace Our.Umbraco.AuthU.Data.Migrations.UmbracoDbOAuthClientStore
5+
{
6+
/// <summary>
7+
/// Simple migration to add a demo client to the OAuthClient Table
8+
/// </summary>
9+
internal class CreateDemoClient : MigrationBase
10+
{
11+
public CreateDemoClient(IMigrationContext context) : base(context)
12+
{ }
13+
14+
public override void Migrate()
15+
{
16+
var existing = Database.SingleOrDefault<OAuthClient>($"SELECT 1 FROM [OAuthClient] WHERE [ClientId] = @0", "DemoClient");
17+
if (existing == null)
18+
{
19+
Database.Save(new OAuthClient
20+
{
21+
ClientId = "DemoClient",
22+
Name = "Demo Client",
23+
Secret = "demo",
24+
SecurityLevel = SecurityLevel.Insecure,
25+
RefreshTokenLifeTime = 14400,
26+
AllowedOrigin = "*"
27+
});
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)