Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using IdentityServer4.Extensions;
using IdentityServer4.Models;
using IdentityServer4.Stores;
using Microsoft.Extensions.Logging;
using OpenActive.FakeDatabase.NET;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -10,11 +11,21 @@ namespace IdentityServer
{
public class AcmePersistedGrantStore : IPersistedGrantStore
{
protected readonly ILogger _logger;

public AcmePersistedGrantStore(ILogger<AcmePersistedGrantStore> logger)
{
_logger = logger;
}

public async Task<IEnumerable<PersistedGrant>> GetAllAsync(PersistedGrantFilter filter)
{
filter.Validate();

var grants = await FakeBookingSystem.Database.GetAllGrants(filter.SubjectId, filter.SessionId, filter.ClientId, filter.Type);

_logger.LogDebug("{persistedGrantCount} persisted grants found for {@filter}", grants.Count, filter);

var persistedGrants = grants.Select(grant => new PersistedGrant
{
Key = grant.Key,
Expand All @@ -23,6 +34,7 @@ public async Task<IEnumerable<PersistedGrant>> GetAllAsync(PersistedGrantFilter
SessionId = grant.SessionId,
ClientId = grant.ClientId,
CreationTime = grant.CreationTime,
ConsumedTime = grant.ConsumedTime,
Expiration = grant.Expiration,
Data = grant.Data
}).ToList();
Expand All @@ -34,6 +46,8 @@ public async Task<PersistedGrant> GetAsync(string key)
{
var grant = await FakeBookingSystem.Database.GetGrant(key);

_logger.LogDebug("{persistedGrantKey} found in database: {persistedGrantKeyFound}", key, grant != null);

return grant != null ? new PersistedGrant
{
Key = grant.Key,
Expand All @@ -42,6 +56,7 @@ public async Task<PersistedGrant> GetAsync(string key)
SessionId = grant.SessionId,
ClientId = grant.ClientId,
CreationTime = grant.CreationTime,
ConsumedTime = grant.ConsumedTime,
Expiration = grant.Expiration,
Data = grant.Data
} : null;
Expand All @@ -51,17 +66,28 @@ public async Task RemoveAllAsync(PersistedGrantFilter filter)
{
filter.Validate();

_logger.LogDebug("removing all persisted grants from database for {@filter}", filter);

await FakeBookingSystem.Database.RemoveAllGrants(filter.SubjectId, filter.SessionId, filter.ClientId, filter.Type);
}

public async Task RemoveAsync(string key)
{
_logger.LogDebug("removing {persistedGrantKey} persisted grant from database", key);

await FakeBookingSystem.Database.RemoveGrant(key);
}

public async Task StoreAsync(PersistedGrant grant)
{
await FakeBookingSystem.Database.AddGrant(grant.Key, grant.Type, grant.SubjectId, grant.SessionId, grant.ClientId, grant.CreationTime, grant.Expiration, grant.Data);
if (await FakeBookingSystem.Database.AddGrant(grant.Key, grant.Type, grant.SubjectId, grant.SessionId, grant.ClientId, grant.CreationTime, grant.ConsumedTime, grant.Expiration, grant.Data))
{
_logger.LogDebug("{persistedGrantKey} not found in database, and so was inserted", grant.Key);
}
else
{
_logger.LogDebug("{persistedGrantKey} found in database, and updated", grant.Key);
}
}
}
}
3 changes: 1 addition & 2 deletions Examples/BookingSystem.AspNetCore.IdentityServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public void ConfigureServices(IServiceCollection services)
.AddInMemoryApiResources(Config.ApiResources)
.AddClientStore<ClientStore>()
.AddFakeUserStore(AppSettings.JsonLdIdBaseUrl)
.AddPersistedGrantStore<AcmePersistedGrantStore>()
.AddProfileService<ProfileService>(); //adding a custom profile service
.AddPersistedGrantStore<AcmePersistedGrantStore>();

services.AddControllersWithViews();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@using OpenActive.FakeDatabase.NET
@model LoginViewModel

<div class="login-page">
Expand All @@ -15,7 +16,7 @@
<div class="col-sm-6">
<div class="card">
<div class="card-header">
<h2>Local Account</h2>
<h2>Seller Account</h2>
</div>

<div class="card-body">
Expand Down Expand Up @@ -84,4 +85,21 @@
</div>
}
</div>
<div class="row mt-5">
<div class="col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Test credentials</h3>
</div>
<div class="panel-body">
<p>Please use the test Seller credentials below to log in:</p>
<div><b>Username</b> &#8594; <b>Password</b></div>
@foreach (var seller in FakeDatabase.DefaultSellerUsers)
{
<div>@seller.Username &#8594; @seller.PasswordRaw</div>
}
</div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<PrivateAssets Condition="'%(PackageReference.Version)' == ''">all</PrivateAssets>
<Publish Condition="'%(PackageReference.Version)' == ''">true</Publish>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureADB2C.UI" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.2" />
<PackageReference Include="OpenActive.NET" Version="15.2.5" />
</ItemGroup>

Expand Down
14 changes: 12 additions & 2 deletions Examples/BookingSystem.AspNetCore/Stores/OrderStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace BookingSystem
{
public class OrderStateContext : IStateContext
{
// OrderStateContext will be disposed at the end of the flow
public void Dispose()
{
}
}

public class AcmeOrderStore : OrderStore<OrderTransaction, OrderStateContext>
Expand Down Expand Up @@ -181,13 +185,19 @@ public override async Task TriggerTestAction(OpenBookingSimulateAction simulateA
}
}

public override ValueTask<OrderStateContext> Initialise(StoreBookingFlowContext flowContext)
public override ValueTask<OrderStateContext> CreateOrderStateContext(StoreBookingFlowContext flowContext)
{
// Runs before the flow starts, for both leasing and booking
// Useful for transferring state between stages of the flow
return new ValueTask<OrderStateContext>(new OrderStateContext());
}

public override ValueTask Initialise(StoreBookingFlowContext flowContext, OrderStateContext stateContext)
{
// Runs before the flow starts, for both leasing and booking
// Simply remove this method if it is not required
return new ValueTask();
}

private static BrokerRole BrokerTypeToBrokerRole(BrokerType brokerType)
{
return brokerType == BrokerType.AgentBroker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,19 @@
<HintPath>..\..\packages\Schema.NET.7.0.1\lib\net461\Schema.NET.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Common, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\ServiceStack.Common.Core.5.10.4\lib\netstandard2.0\ServiceStack.Common.dll</HintPath>
<HintPath>..\..\packages\ServiceStack.Common.Core.5.11.0\lib\netstandard2.0\ServiceStack.Common.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\ServiceStack.Interfaces.Core.5.10.4\lib\netstandard2.0\ServiceStack.Interfaces.dll</HintPath>
<HintPath>..\..\packages\ServiceStack.Interfaces.Core.5.11.0\lib\netstandard2.0\ServiceStack.Interfaces.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.OrmLite, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\ServiceStack.OrmLite.Core.5.10.4\lib\netstandard2.0\ServiceStack.OrmLite.dll</HintPath>
<HintPath>..\..\packages\ServiceStack.OrmLite.Core.5.11.0\lib\netstandard2.0\ServiceStack.OrmLite.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.OrmLite.Sqlite, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\ServiceStack.OrmLite.Sqlite.Core.5.10.4\lib\netstandard2.0\ServiceStack.OrmLite.Sqlite.dll</HintPath>
<HintPath>..\..\packages\ServiceStack.OrmLite.Sqlite.Core.5.11.0\lib\netstandard2.0\ServiceStack.OrmLite.Sqlite.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Text, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\ServiceStack.Text.Core.5.10.4\lib\netstandard2.0\ServiceStack.Text.dll</HintPath>
<HintPath>..\..\packages\ServiceStack.Text.Core.5.11.0\lib\netstandard2.0\ServiceStack.Text.dll</HintPath>
</Reference>
<Reference Include="Stubble.Core, Version=1.7.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Stubble.Core.1.7.2\lib\net45\Stubble.Core.dll</HintPath>
Expand Down
14 changes: 12 additions & 2 deletions Examples/BookingSystem.AspNetFramework/Stores/OrderStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace BookingSystem
{
public class OrderStateContext : IStateContext
{
// OrderStateContext will be disposed at the end of the flow
public void Dispose()
{
}
}

public class AcmeOrderStore : OrderStore<OrderTransaction, OrderStateContext>
Expand Down Expand Up @@ -181,13 +185,19 @@ public override async Task TriggerTestAction(OpenBookingSimulateAction simulateA
}
}

public override ValueTask<OrderStateContext> Initialise(StoreBookingFlowContext flowContext)
public override ValueTask<OrderStateContext> CreateOrderStateContext(StoreBookingFlowContext flowContext)
{
// Runs before the flow starts, for both leasing and booking
// Useful for transferring state between stages of the flow
return new ValueTask<OrderStateContext>(new OrderStateContext());
}

public override ValueTask Initialise(StoreBookingFlowContext flowContext, OrderStateContext stateContext)
{
// Runs before the flow starts, for both leasing and booking
// Simply remove this method if it is not required
return new ValueTask();
}

private static BrokerRole BrokerTypeToBrokerRole(BrokerType brokerType)
{
return brokerType == BrokerType.AgentBroker
Expand Down
10 changes: 5 additions & 5 deletions Examples/BookingSystem.AspNetFramework/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@
<package id="Owin" version="1.0" targetFramework="net461" />
<package id="Schema.NET" version="7.0.1" targetFramework="net461" />
<package id="ServiceStack.Common" version="5.10.4" targetFramework="net461" />
<package id="ServiceStack.Common.Core" version="5.10.4" targetFramework="net461" />
<package id="ServiceStack.Common.Core" version="5.11.0" targetFramework="net461" />
<package id="ServiceStack.Interfaces" version="5.10.4" targetFramework="net461" />
<package id="ServiceStack.Interfaces.Core" version="5.10.4" targetFramework="net461" />
<package id="ServiceStack.Interfaces.Core" version="5.11.0" targetFramework="net461" />
<package id="ServiceStack.OrmLite" version="5.10.4" targetFramework="net461" />
<package id="ServiceStack.OrmLite.Core" version="5.10.4" targetFramework="net461" />
<package id="ServiceStack.OrmLite.Sqlite.Core" version="5.10.4" targetFramework="net461" />
<package id="ServiceStack.OrmLite.Core" version="5.11.0" targetFramework="net461" />
<package id="ServiceStack.OrmLite.Sqlite.Core" version="5.11.0" targetFramework="net461" />
<package id="ServiceStack.Text" version="5.10.4" targetFramework="net461" />
<package id="ServiceStack.Text.Core" version="5.10.4" targetFramework="net461" />
<package id="ServiceStack.Text.Core" version="5.11.0" targetFramework="net461" />
<package id="Stub.System.Data.SQLite.Core.NetFramework" version="1.0.113.3" targetFramework="net461" />
<package id="Stubble.Core" version="1.7.2" targetFramework="net461" />
<package id="Stubble.Extensions.JsonNet.Net45" version="1.3.3" targetFramework="net461" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="NPoco" Version="4.0.2" />
<PackageReference Include="OpenActive.NET" Version="15.2.5" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
Expand Down
7 changes: 4 additions & 3 deletions Fakes/OpenActive.FakeDatabase.NET/FakeBookingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@ public async Task<GrantTable> GetGrant(string key)
return await db.SingleAsync<GrantTable>(x => x.Key == key);
}
}
public async Task<IEnumerable<GrantTable>> GetAllGrants(string subjectId, string sessionId, string clientId, string type)
public async Task<List<GrantTable>> GetAllGrants(string subjectId, string sessionId, string clientId, string type)
{
using (var db = await Mem.Database.OpenAsync())
{
Expand All @@ -1687,7 +1687,7 @@ public async Task<IEnumerable<GrantTable>> GetAllGrants(string subjectId, string
}
}

public async Task AddGrant(string key, string type, string subjectId, string sessionId, string clientId, DateTime creationTime, DateTime? expiration, string data)
public async Task<bool> AddGrant(string key, string type, string subjectId, string sessionId, string clientId, DateTime creationTime, DateTime? consumedTime, DateTime? expiration, string data)
{
using (var db = await Mem.Database.OpenAsync())
{
Expand All @@ -1699,10 +1699,11 @@ public async Task AddGrant(string key, string type, string subjectId, string ses
SessionId = sessionId,
ClientId = clientId,
CreationTime = creationTime,
ConsumedTime = consumedTime,
Expiration = expiration,
Data = data
};
await db.SaveAsync(grant);
return await db.SaveAsync(grant);
}
}

Expand Down
3 changes: 3 additions & 0 deletions Fakes/OpenActive.FakeDatabase.NET/Models/GrantTable.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using ServiceStack.DataAnnotations;
using System;

namespace OpenActive.FakeDatabase.NET
{
public class GrantTable
{
[PrimaryKey]
public string Key { get; set; }
public string Type { get; set; }
public string SubjectId { get; set; }
public string SessionId { get; set; }
public string ClientId { get; set; }
public DateTime CreationTime { get; set; }
public DateTime? ConsumedTime { get; set; }
public DateTime? Expiration { get; set; }
public string Data { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<ItemGroup>
<PackageReference Include="Bogus" Version="33.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ServiceStack.OrmLite.Sqlite.Core" Version="5.9.2" />
<PackageReference Include="ServiceStack.OrmLite.Sqlite.Core" Version="5.11.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="OpenActive.NET" Version="15.2.5" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,15 @@ public static class OpenActiveScopes
/// Seller identity scope
/// </summary>
public const string SellerIdentity = "openactive-identity";

/// <summary>
/// Customer Account endpoint scope
/// </summary>
public const string CustomerAccountModify = "openactive-customeraccount-modify";

/// <summary>
/// Customer Accoun query endpoint scope
/// </summary>
public const string CustomerAccountQuery = "openactive-customeraccount-query";
}
}
Loading