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
Expand Up @@ -20,5 +20,7 @@ public class ApiKey
//public DateTime ValidTo { get; set; } // TODO: Add support for time-activated API keys.

public IReadOnlyCollection<string> Roles { get; set; }

public IReadOnlyCollection<string> Paths { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()

if (existingApiKey != null)
{
// First verify the path access is enabled, if so we'll perform a validation here.
if (this.Request.Path.HasValue && existingApiKey.Paths != null && existingApiKey.Paths.Count > 0)
{
string path = this.Request.Path.Value;
bool hasAccess = existingApiKey.Paths.Any(p => path.StartsWith(p));

if (!hasAccess)
{
// Return NoResult and return standard 401 Unauthorized result.
return AuthenticateResult.NoResult();
}
}

var claims = new List<Claim>
{
new Claim(ClaimTypes.Name, existingApiKey.Owner)
Expand Down
3 changes: 3 additions & 0 deletions src/Features/Blockcore.Features.NodeHost/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public void ConfigureServices(IServiceCollection services)
{
NodeHostSettings hostSettings = fullNode.Services.ServiceProvider.GetService<NodeHostSettings>();

// Make the configuration available to custom features.
services.AddSingleton(this.Configuration);

services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddConfiguration(this.Configuration.GetSection("Logging"));
Expand Down
13 changes: 0 additions & 13 deletions src/Features/Blockcore.Features.NodeHost/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,5 @@
"System": "Information",
"Microsoft": "Information"
}
},
"Blockcore": {
"API": {
"Keys": [
{
"Id": 1,
"Enabled": false,
"Owner": "Admin",
"Key": "1ca8f906-a23e-48b2-8b83-e95290986d0e",
"Roles": [ "User", "Admin" ]
}
]
}
}
}
31 changes: 31 additions & 0 deletions src/Node/Blockcore.Node/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Information",
"System": "Information",
"Microsoft": "Information"
}
},
"Blockcore": {
"API": {
"Keys": [
{
"Id": 1,
"Enabled": false,
"Owner": "Admin",
"Key": "1ca8f906-a23e-48b2-8b83-e95290986d0e",
"Roles": [ "User", "Admin" ]
},
{
"Id": 2,
"Enabled": false,
"Owner": "Registry",
"Key": "132525f1-46d2-45eb-bfe5-8a354b63ce36",
"Roles": [ "User" ],
"Paths": [ "/api/identity", "/api/storage", "/.well-known" ]
}
]
}
}
}