Skip to content

Commit 4738ae5

Browse files
Merge branch 'develop'
2 parents 4b528a1 + 77da43d commit 4738ae5

30 files changed

+479
-409
lines changed

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,30 @@ AuthU is an add-on library to [Umbraco](https://github.com/umbraco/umbraco-cms)
77

88
PM> Install-Package Our.Umbraco.AuthU
99

10-
There's also a nightly Nuget feed: [`https://www.myget.org/F/umbraco-authu/api/v2`](https://www.myget.org/F/umbraco-authu/api/v2)
11-
1210
## Configuration
13-
AuthU is configured using the `OAuth.ConfigureEndpoint` helper inside an Umbraco `ApplicationEventHandler` like so:
14-
````csharp
15-
public class Boostrap : ApplicationEventHandler
11+
In order to configure AuthU you will first of all need to create an Umbraco composer + compontent combination like so:
12+
````csharp
13+
public class AuthUConfigComponent : IComponent
1614
{
17-
protected override void ApplicationStarted(UmbracoApplicationBase app, ApplicationContext ctx)
15+
public void Initialize()
1816
{
19-
OAuth.ConfigureEndpoint(...);
17+
// Configuration goes here
2018
}
19+
20+
public void Terminate() { }
2121
}
22+
23+
public class AuthUConfigComposer : ComponentComposer<AuthUConfigComponent>
24+
{ }
2225
````
26+
27+
From within the `Initialize` method, you can then configure your endpoint(s) via the `OAuth.ConfigureEndpoint` helper like so:
28+
````csharp
29+
...
30+
OAuth.ConfigureEndpoint(...);
31+
...
32+
````
33+
2334
### Basic Configuration
2435
For the most basic OAuth implementation, the following minimal configuration is all that is needed:
2536
````csharp

appveyor.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
image: Visual Studio 2017
22

33
# version format
4-
version: 1.0.3.{build}
4+
version: 1.0.4.{build}
55

66
# UMBRACO_PACKAGE_PRERELEASE_SUFFIX if a rtm release build this should be blank, otherwise if empty will default to alpha
77
# example UMBRACO_PACKAGE_PRERELEASE_SUFFIX=beta
@@ -22,15 +22,6 @@ artifacts:
2222
- path: artifacts\*.zip
2323

2424
deploy:
25-
# MyGet Deployment for builds & releases
26-
- provider: NuGet
27-
server: https://www.myget.org/F/umbraco-authu/api/v2/package
28-
symbol_server: https://www.myget.org/F/umbraco-authu/symbols/api/v2/package
29-
api_key:
30-
secure: gHDTL46KZcLzj6J8m//TJgaCOJCl9ixR//rXjO18HRlCsfPYYz7dU81u2D5zd+ZN
31-
artifact: /.*\.nupkg/
32-
on:
33-
branch: develop
3425

3526
# GitHub Deployment for releases
3627
- provider: GitHub
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Umbraco.Core;
2+
using Umbraco.Core.Composing;
3+
4+
namespace Our.Umbraco.AuthU.Composing
5+
{
6+
/// <summary>
7+
/// This class registers components at umbraco start up.
8+
/// </summary>
9+
internal class MigrationRunnerComposer : IUserComposer
10+
{
11+
public void Compose(Composition composition)
12+
{
13+
// Registers the Migrations Runner component, this creates the tables
14+
// required for the oAuth stores.
15+
composition.Components().Append<MigrationsRunnerComponent>();
16+
}
17+
}
18+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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;
9+
10+
namespace Our.Umbraco.AuthU.Composing
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+
var plan = new AuthUMigrationPlan();
36+
var upgrader = new Upgrader(plan);
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+
}

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;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Umbraco.Core.Migrations;
2+
3+
namespace Our.Umbraco.AuthU.Data.Migrations
4+
{
5+
/// <summary>
6+
/// Simple migration to create the DeviceId column on the OAuthRefreshToken Table
7+
/// </summary>
8+
internal class AddDeviceIdColumnToOAuthRefreshTokenTable : MigrationBase
9+
{
10+
public AddDeviceIdColumnToOAuthRefreshTokenTable(IMigrationContext context) : base(context)
11+
{ }
12+
13+
public override void Migrate()
14+
{
15+
if (!ColumnExists("OAuthRefreshToken", "DeviceId"))
16+
Alter.Table("OAuthRefreshToken").AddColumn("DeviceId").AsString().Nullable();
17+
}
18+
19+
}
20+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Umbraco.Core.Migrations;
2+
3+
namespace Our.Umbraco.AuthU.Data.Migrations
4+
{
5+
/// <summary>
6+
/// This is the plan that runs the AuthU Migrations
7+
/// </summary>
8+
internal class AuthUMigrationPlan : MigrationPlan
9+
{
10+
/// <summary>
11+
/// Add the demo id if preferred
12+
/// </summary>
13+
/// <param name="CreateDemoClient"></param>
14+
public AuthUMigrationPlan() : base("AuthU")
15+
{
16+
From(InitialState)
17+
.To<CreateOAuthClientTable>("CreateOAuthClientTable")
18+
.To<CreateOAuthRefreshTokenTable>("CreateOAuthRefreshTokenTable")
19+
.To<AddDeviceIdColumnToOAuthRefreshTokenTable>("AddDeviceIdColumnToOAuthRefreshTokenTable")
20+
.To<CreateDemoOAuthClient>("CreateDemoOAuthClient");
21+
}
22+
23+
/// <summary>
24+
/// Using the helper method to get the AuthU Key 'Umbraco.Core.Upgrader.State+AuthU' Value
25+
/// </summary>
26+
public override string InitialState => string.Empty;
27+
}
28+
}

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

Lines changed: 0 additions & 31 deletions
This file was deleted.
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
5+
{
6+
/// <summary>
7+
/// Simple migration to add a demo client to the OAuthClient Table
8+
/// </summary>
9+
internal class CreateDemoOAuthClient : MigrationBase
10+
{
11+
public CreateDemoOAuthClient(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+
}
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
5+
{
6+
/// <summary>
7+
/// Simple migration to create the OAuthClient Table
8+
/// </summary>
9+
internal class CreateOAuthClientTable : MigrationBase
10+
{
11+
public CreateOAuthClientTable(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+
}

0 commit comments

Comments
 (0)