Skip to content

Commit

Permalink
Create img folder and add logo.
Browse files Browse the repository at this point in the history
Add versioning in identity grpc.
  • Loading branch information
a-sharifov committed Feb 5, 2024
1 parent 095c0e0 commit 7bf14d9
Show file tree
Hide file tree
Showing 22 changed files with 125 additions and 50 deletions.
2 changes: 1 addition & 1 deletion crs/CommonComponents/Contracts/Contracts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<ItemGroup>
<Protobuf Include="Abstractions\Abstractions.proto" GrpcServices="Both" />
<Protobuf Include="Services\Identity\Identity.proto" GrpcServices="Both" />
<Protobuf Include="Services\Identity\identity.v1.proto" GrpcServices="Both" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
syntax = "proto3";

option csharp_namespace = "Contracts.Services.Identity";

package identity;
package identity.v1;

service IdentityService {
rpc GetUser(GetUserRequest) returns (User);
rpc GetUserInfo(GetUserRequest) returns (UserInfo);
}

message GetUserRequest {
string id = 1;
}

message User {
message UserInfo {
string user_id = 1;
string email = 2;
string first_name = 3;
Expand Down
27 changes: 15 additions & 12 deletions crs/Docker/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,21 @@ services:

email.app:
environment:
- ASPNETCORE_URLS=http://+:80
- ASPNETCORE_HTTP_PORTS=5110
- ASPNETCORE_ENVIRONMENT=Development
# Custom environment variables
- Email__From=${EMAIL_FROM}}
- Email__Host=${EMAIL_HOST}
- Email__Port=${EMAIL_PORT}
- Email__Username=${EMAIL_USERNAME}
- Email__Password=${EMAIL_PASSWORD}
- Retry__Message__Send__Count=3
- RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS}
- ASPNETCORE_URLS=http://+:80
- ASPNETCORE_HTTP_PORTS=5110
- ASPNETCORE_ENVIRONMENT=Development
# Custom environment variables
- Email__From=${EMAIL_FROM}}
- Email__Host=${EMAIL_HOST}
- Email__Port=${EMAIL_PORT}
- Email__Username=${EMAIL_USERNAME}
- Email__Password=${EMAIL_PASSWORD}
- Retry__Message__Send__Count=3
- RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS}
- AUTH_ISSUER=${AUTH_ISSUER}
- WEB_AUDIENCE=${WEB_AUDIENCE}
- JWT_SECURITY_KEY=${JWT_SECURITY_KEY}
ports:
- "5110:80"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;

namespace Catalog.App.Configurations;
namespace Catalog.App.Configurations;

internal sealed class AuthenticationAuthorizationServiceInstaller : IServiceInstaller
{
Expand Down
3 changes: 2 additions & 1 deletion crs/Services/Catalog/Catalog.App/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
global using OpenTelemetry.Metrics;
global using Prometheus;
global using Common.App.HealthChecks;
global using Common.App.HealthChecks;
global using Microsoft.AspNetCore.Authentication.JwtBearer;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@ internal sealed class AuthenticationAuthorizationServiceInstaller : IServiceInst
{
public void Install(IServiceCollection services, IConfiguration configuration)
{
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, configureOptions =>
{
configureOptions.RequireHttpsMetadata = true;
configureOptions.SaveToken = true;
configureOptions.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = Env.AUTH_ISSUER,
ValidateAudience = true,
ValidAudiences = [Env.WEB_AUDIENCE],
RequireExpirationTime = true,
ValidateLifetime = true,
ClockSkew = TimeSpan.Zero,
RoleClaimType = ClaimTypes.Role,
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(Env.JWT_SECURITY_KEY)),
};
});

services.AddAuthorization();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ internal sealed class GrpcServiceInstaller : IServiceInstaller
{
public void Install(IServiceCollection services, IConfiguration configuration)
{
services.AddGrpcClient<IdentityService.IdentityServiceClient>(options =>
services.AddGrpcClient<Identity.V1.IdentityService.IdentityServiceClient>(options =>
{
options.Address = new Uri(Env.IDENTITY_URL);
});
Expand Down
1 change: 1 addition & 0 deletions crs/Services/Email/Email.App/Email.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.0" />
<PackageReference Include="Grpc.AspNetCore" Version="2.60.0" />
<PackageReference Include="MailKit" Version="4.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="NetEscapades.Configuration.Yaml" Version="3.1.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.7.0" />
Expand Down
3 changes: 3 additions & 0 deletions crs/Services/Email/Email.App/Env.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ internal static class Env
public static string IDENTITY_URL => GetEnvironmentVariable("IDENTITY_URL");
public static string RABBITMQ_DEFAULT_USER => GetEnvironmentVariable("RABBITMQ_DEFAULT_USER");
public static string RABBITMQ_DEFAULT_PASS => GetEnvironmentVariable("RABBITMQ_DEFAULT_PASS");
public static string AUTH_ISSUER => GetEnvironmentVariable("AUTH_ISSUER");
public static string WEB_AUDIENCE => GetEnvironmentVariable("WEB_AUDIENCE");
public static string JWT_SECURITY_KEY => GetEnvironmentVariable("JWT_SECURITY_KEY");

public static class ConnectionString
{
Expand Down
6 changes: 5 additions & 1 deletion crs/Services/Email/Email.App/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
global using FluentValidation;
global using Email.App.OptionsSetup;
global using Common.Infrastructure.Middleware;
global using Contracts.Services.Identity;
global using Contracts.Services.Identity;
global using Microsoft.AspNetCore.Authentication.JwtBearer;
global using Microsoft.IdentityModel.Tokens;
global using System.Security.Claims;
global using System.Text;
1 change: 0 additions & 1 deletion crs/Services/Identity/Idenitty.Grpc/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
global using Grpc.Core;
global using Contracts.Services.Identity;
global using MediatR;
1 change: 1 addition & 0 deletions crs/Services/Identity/Idenitty.Grpc/Idenitty.Grpc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<ItemGroup>
<ProjectReference Include="..\..\..\CommonComponents\Contracts\Contracts.csproj" />
<ProjectReference Include="..\Identity.Application\Identity.Application.csproj" />
</ItemGroup>

</Project>
13 changes: 0 additions & 13 deletions crs/Services/Identity/Idenitty.Grpc/IdentityGrpcService.cs

This file was deleted.

24 changes: 24 additions & 0 deletions crs/Services/Identity/Idenitty.Grpc/IdentityGrpcServiceV1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Identity.Application.Users.Queries.GetUserInfoById;
using Identity.V1;

namespace Idenitty.Grpc;

public sealed class IdentityGrpcServiceV1(ISender sender) : IdentityService.IdentityServiceBase
{
private readonly ISender _sender = sender;

public override async Task<UserInfo> GetUserInfo(GetUserRequest request, ServerCallContext context)
{
Guid.TryParse(request.Id, out Guid userId);

//if(userId == Guid.Empty)
//{
// context.Status = new Status(StatusCode.InvalidArgument, "Invalid user id");
//}

var query = new GetUserInfoByIdQuery(userId);
var result = await _sender.Send(query);
var response = new UserInfo() { s};
return base.GetUser(request, context);
}
}
2 changes: 1 addition & 1 deletion crs/Services/Identity/Identity.App/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
configure.MapControllers();
configure.MapPrometheusScrapingEndpoint();
configure.MapGrpcService<IdentityGrpcService>();
configure.MapGrpcService<IdentityGrpcServiceV1>();
configure.MapHealthChecks("/health", new HealthCheckOptions
{
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
Expand Down
3 changes: 2 additions & 1 deletion crs/Services/Identity/Identity.Application/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
global using EventBus.Common.Abstractions;
global using Contracts.Services.Identity.Commands;
global using Identity.Infrastructure.Hashing;
global using Identity.Infrastructure.Authentication;
global using Identity.Infrastructure.Authentication;
global using Identity.Application.Users.Common;
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,4 @@
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.3.1" />
</ItemGroup>

<ItemGroup>
<Folder Include="Users\Common\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Identity.Application.Users.Common;

public sealed record UserInfo(
Guid UserId,
string Email,
string FirstName,
string LastName,
bool IsEmailConfirmed,
string Role,
string Gender);

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Identity.Application.Users.Queries.GetUserInfoById;

public sealed record GetUserInfoByIdQuery(Guid Id) : IQuery<UserInfo>;

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Identity.Application.Users.Queries.GetUserInfoById;

internal sealed class GetUserInfoByIdQueryHandler(IUserRepository userRepository) : IQueryHandler<GetUserInfoByIdQuery, UserInfo>
{
private readonly IUserRepository _userRepository = userRepository;

public async Task<Result<UserInfo>> Handle(GetUserInfoByIdQuery request, CancellationToken cancellationToken)
{
var userId = new UserId(request.Id);

var user = await _userRepository.GetUserByIdAsync(userId, cancellationToken);

if (user is null)
{
return Result.Failure<UserInfo>(
UserErrors.UserDoesNotExist);
}

var userInfo = new UserInfo(
user.Id,
user.Email.Value,
user.(r => r.Name).ToList());

return Result.Success(userInfo);
}
}
Binary file added img/Eshop_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7bf14d9

Please sign in to comment.