Skip to content

Commit 5aef50f

Browse files
authored
chore(identity): configure partial identity (#1)
* feat(applications): add create application endpoint
1 parent 444c1a4 commit 5aef50f

25 files changed

+501
-79
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-alpine3.9 as build
1+
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine as build
22
WORKDIR /app
33
COPY . .
44
RUN dotnet restore
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Micro.AppRegistration.Api.Auth
2+
{
3+
public class CustomClaims
4+
{
5+
public const string Permission = "Permission";
6+
}
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace Micro.AppRegistration.Api.Auth.Exceptions
4+
{
5+
public class KeyNotFoundException : Exception
6+
{
7+
public KeyNotFoundException(string message) : base(message)
8+
{
9+
}
10+
}
11+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Threading.Tasks;
2+
using Fossapps.Micro.KeyStore;
3+
using Fossapps.Micro.KeyStore.Models;
4+
using Micro.AppRegistration.Api.Auth.Exceptions;
5+
6+
namespace Micro.AppRegistration.Api.Auth
7+
{
8+
public interface IKeyResolver
9+
{
10+
Task<string> ResolveKey(string keyId);
11+
}
12+
public class KeyResolver : IKeyResolver
13+
{
14+
private readonly IKeyStoreClient _keyStoreClient;
15+
16+
public KeyResolver(IKeyStoreClient keyStoreClient)
17+
{
18+
_keyStoreClient = keyStoreClient;
19+
}
20+
21+
public async Task<string> ResolveKey(string keyId)
22+
{
23+
var response = await _keyStoreClient.Keys.GetAsync(keyId);
24+
return response switch
25+
{
26+
KeyCreatedResponse keyCreatedResponse => keyCreatedResponse.Body,
27+
_ => throw new KeyNotFoundException($"key: '{keyId}' not found")
28+
};
29+
}
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Linq;
3+
using Microsoft.AspNetCore.Authorization;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Microsoft.AspNetCore.Mvc.Filters;
6+
7+
namespace Micro.AppRegistration.Api.Auth
8+
{
9+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
10+
public class RequirePermission : Attribute, IAuthorizeData, IAuthorizationFilter
11+
{
12+
public string AuthenticationSchemes { get; set; }
13+
public string Policy { get; set; }
14+
public string Roles { get; set; }
15+
private readonly string _permission;
16+
17+
public RequirePermission(string permission)
18+
{
19+
_permission = permission;
20+
}
21+
22+
public void OnAuthorization(AuthorizationFilterContext context)
23+
{
24+
var permissionClaims = context.HttpContext?.User?.Claims?.Where(c => c.Type == CustomClaims.Permission);
25+
var hasClaim = permissionClaims?.Any(x => x.Value == _permission || x.Value == "sudo");
26+
if (!hasClaim.HasValue || !hasClaim.Value)
27+
{
28+
context.Result = new ForbidResult();
29+
}
30+
}
31+
}
32+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Micro.AppRegistration.Api.Configs
2+
{
3+
public class Services
4+
{
5+
public KeyStoreConfig KeyStore { set; get; }
6+
}
7+
8+
public class KeyStoreConfig
9+
{
10+
public string Url { set; get; }
11+
}
12+
}

Micro.AppRegistration.Api/Controllers/AppRegistrationController.cs

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

Micro.AppRegistration.Api/Controllers/CreateApplicationRequest.cs

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

Micro.AppRegistration.Api/Controllers/WeatherForecast.cs

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

Micro.AppRegistration.Api/Controllers/WeatherForecastController.cs

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

0 commit comments

Comments
 (0)