Skip to content

Commit e15082f

Browse files
authored
Merge pull request #1 from OpenPerpetuum/feature/openidserver
Add OpenID Connect and Perpetuum Account Authentication
2 parents 2850f3a + 03211b9 commit e15082f

55 files changed

Lines changed: 1990 additions & 90 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/.vscode/launch.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
// Use IntelliSense to find out which attributes exist for C# debugging
3+
// Use hover for the description of the existing attributes
4+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": ".NET Core Launch (web)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/OpenPerpetuum.Api/bin/Debug/netcoreapp2.1/OpenPerpetuum.Api.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}/OpenPerpetuum.Api",
16+
"stopAtEntry": false,
17+
"internalConsoleOptions": "openOnSessionStart",
18+
"launchBrowser": {
19+
"enabled": true,
20+
"args": "${auto-detect-url}",
21+
"windows": {
22+
"command": "cmd.exe",
23+
"args": "/C start ${auto-detect-url}"
24+
},
25+
"osx": {
26+
"command": "open"
27+
},
28+
"linux": {
29+
"command": "xdg-open"
30+
}
31+
},
32+
"env": {
33+
"ASPNETCORE_ENVIRONMENT": "Development"
34+
},
35+
"sourceFileMap": {
36+
"/Views": "${workspaceFolder}/Views"
37+
}
38+
},
39+
{
40+
"name": ".NET Core Attach",
41+
"type": "coreclr",
42+
"request": "attach",
43+
"processId": "${command:pickProcess}"
44+
}
45+
,]
46+
}

src/.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

src/.vscode/tasks.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/OpenPerpetuum.Api/OpenPerpetuum.Api.csproj",
11+
"-o ${workspaceFolder}/bin"
12+
],
13+
"problemMatcher": "$msCompile"
14+
}
15+
]
16+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
create database api; -- Bler; sort this out with something a little more explicit please (I hate leaving things in the hands of SQL Server) =)
2+
go
3+
4+
begin transaction CREATE_API_DB
5+
set xact_abort on
6+
set transaction isolation level read committed
7+
8+
use api
9+
10+
if not exists (select * from sys.schemas where name = 'Authorisation')
11+
exec('create schema Authorisation'); -- Allows it to run in its own batch
12+
13+
if not exists (select * from sys.server_principals where type = 'S' and name='api_mgmt_user')
14+
create login api_mgmt_user with password='ChangeMe';
15+
16+
if not exists (select * from sys.database_principals where type = 'S' and name='api_mgmt_user')
17+
create user api_mgmt_user for login api_mgmt_user with default_schema=dbo;
18+
19+
grant EXECUTE on schema :: dbo to api_mgmt_user;
20+
grant EXECUTE on schema :: Authorisation to api_mgmt_user;
21+
22+
create table api.dbo.DBPatchVersion
23+
(
24+
PatchId int not null,
25+
PatchName nvarchar(500) not null,
26+
VersionNumber nvarchar(30) not null,
27+
DateApplied datetimeoffset not null,
28+
MessageLog nvarchar(max) null,
29+
constraint PK_DBPatchVersion_PatchId primary key (PatchId),
30+
constraint UQ_DBPatchVersion_VersionNumber unique (VersionNumber)
31+
);
32+
33+
insert into api.dbo.DBPatchVersion
34+
(
35+
PatchId,
36+
PatchName,
37+
VersionNumber,
38+
DateApplied,
39+
MessageLog
40+
)
41+
values
42+
(
43+
1000,
44+
'Create_Database_Init',
45+
'1.000',
46+
getdate(),
47+
'Initialised database with baseline settings'
48+
);
49+
50+
commit transaction CREATE_API_DB;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<PatchControl>
2+
<SchemaPatch filename="SchemaPatch1_001.sql" version="1.001" dependency="1.000" />
3+
</PatchControl>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
************************
3+
Patch Version: 1.001
4+
Written By: Marakai
5+
Description: Create the table for storing the AccessClients (third party allowed applications)
6+
Depends On: 1.000
7+
************************
8+
*/
9+
10+
create table AccessClient
11+
(
12+
ClientId uniqueidentifier not null,
13+
FriendlyName nvarchar(500) not null,
14+
AdministratorContactAddress nvarchar(max) not null,
15+
AdministratorName nvarchar(max) not null,
16+
RedirectUri nvarchar(500) not null,
17+
SecretKey nvarchar(100) not null,
18+
IsAdministratorApp bit not null,
19+
constraint PK_AccessClient_ClientId primary key (ClientId),
20+
constraint UQ_AccessClient_FriendlyName unique (FriendlyName),
21+
constraint UQ_AccessClient_RedirectUri unique (RedirectUri),
22+
constraint UQ_AccessClient_SecretKey unique (SecretKey)
23+
)
24+
25+
-- Ensure there is only one administrator app so that we control it. This prevents hard-coding the ClientId, making it easier to recover in the event of a compromise
26+
create unique index UQF_AccessClient_IsAdministratorApp on AccessClient (IsAdministratorApp) where IsAdministratorApp = 1;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
if object_id('Authorisation.GetAccessClients', 'P') is not null
2+
drop procedure Authorisation.GetAccessClients;
3+
go
4+
5+
create procedure Authorisation.GetAccessClients
6+
@ClientId uniqueidentifier null
7+
as
8+
9+
select
10+
ClientId,
11+
FriendlyName,
12+
AdministratorContactAddress,
13+
AdministratorName,
14+
RedirectUri,
15+
SecretKey,
16+
IsAdministratorApp
17+
from AccessClient
18+
where (@ClientId is null or ClientId = @ClientId);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<ProcedureControl>
2+
<StoredProcedure name="Authorisation.GetAccessClients" filename="Authorisation.GetAccessClients.sql" />
3+
</ProcedureControl>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<PatchControl>
2+
<SchemaPatch filename="SchemaPatch1_001.sql" version="1.001" />
3+
</PatchControl>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
************************
3+
Patch Version: 1.001
4+
Written By: Marakai
5+
Description: Create the user and access rights for the API
6+
Depends On: None
7+
************************
8+
*/
9+
10+
begin transaction CREATE_API_USER
11+
set xact_abort on
12+
set transaction isolation level read committed
13+
14+
if not exists (select * from sys.schemas where name = 'API')
15+
exec('create schema API'); -- Allows it to run in its own batch
16+
17+
if not exists (select * from sys.server_principals where type = 'S' and name='api_user')
18+
create login api_user with password='ChangeMe';
19+
20+
if not exists (select * from sys.database_principals where type = 'S' and name='api_user')
21+
create user api_user for login api_user with default_schema=dbo;
22+
23+
grant EXECUTE on schema :: dbo to api_user;
24+
grant EXECUTE on schema :: API to api_user;
25+
26+
create table dbo.DBPatchVersion
27+
(
28+
PatchId int not null,
29+
PatchName nvarchar(500) not null,
30+
VersionNumber nvarchar(30) not null,
31+
DateApplied datetimeoffset not null,
32+
MessageLog nvarchar(max) null,
33+
constraint PK_DBPatchVersion_PatchId primary key (PatchId),
34+
constraint UQ_DBPatchVersion_VersionNumber unique (VersionNumber)
35+
);
36+
37+
insert into dbo.DBPatchVersion
38+
(
39+
PatchId,
40+
PatchName,
41+
VersionNumber,
42+
DateApplied,
43+
MessageLog
44+
)
45+
values
46+
(
47+
1000,
48+
'Create_Database_Init',
49+
'1.000',
50+
getdate(),
51+
'Initialised database with baseline settings'
52+
);
53+
54+
commit transaction CREATE_API_USER;

0 commit comments

Comments
 (0)