Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to new structure and multi tenancy #12

Merged
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 @@ -707,6 +707,7 @@ public partial class AddUserRequestContract : System.ComponentModel.INotifyPrope
{
private string _userName;
private string _password;
private string _whiteLabelKey;

[Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string UserName
Expand Down Expand Up @@ -738,6 +739,21 @@ public string Password
}
}

[Newtonsoft.Json.JsonProperty("whiteLabelKey", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string WhiteLabelKey
{
get { return _whiteLabelKey; }

set
{
if (_whiteLabelKey != value)
{
_whiteLabelKey = value;
RaisePropertyChanged();
}
}
}

public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

protected virtual void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
Expand All @@ -751,8 +767,24 @@ protected virtual void RaisePropertyChanged([System.Runtime.CompilerServices.Cal
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.3.0))")]
public partial class ApplicationInitializeRequestContract : System.ComponentModel.INotifyPropertyChanged
{
private string _whiteLabelKey;
private string _language;

[Newtonsoft.Json.JsonProperty("whiteLabelKey", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string WhiteLabelKey
{
get { return _whiteLabelKey; }

set
{
if (_whiteLabelKey != value)
{
_whiteLabelKey = value;
RaisePropertyChanged();
}
}
}

[Newtonsoft.Json.JsonProperty("language", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string Language
{
Expand Down Expand Up @@ -1595,10 +1627,26 @@ protected virtual void RaisePropertyChanged([System.Runtime.CompilerServices.Cal
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.3.0))")]
public partial class UserClaimContract : System.ComponentModel.INotifyPropertyChanged
{
private string _whiteLabelKey;
private string _userName;
private string _password;
private System.Collections.Generic.ICollection<ClaimContract> _claims;

[Newtonsoft.Json.JsonProperty("whiteLabelKey", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string WhiteLabelKey
{
get { return _whiteLabelKey; }

set
{
if (_whiteLabelKey != value)
{
_whiteLabelKey = value;
RaisePropertyChanged();
}
}
}

[Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string UserName
{
Expand Down Expand Up @@ -1765,9 +1813,25 @@ protected virtual void RaisePropertyChanged([System.Runtime.CompilerServices.Cal
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.3.0))")]
public partial class UserSummaryContract : System.ComponentModel.INotifyPropertyChanged
{
private string _whiteLabelKey;
private string _userName;
private string _password;

[Newtonsoft.Json.JsonProperty("whiteLabelKey", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string WhiteLabelKey
{
get { return _whiteLabelKey; }

set
{
if (_whiteLabelKey != value)
{
_whiteLabelKey = value;
RaisePropertyChanged();
}
}
}

[Newtonsoft.Json.JsonProperty("userName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string UserName
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,21 @@
"password": {
"type": "string",
"nullable": true
},
"whiteLabelKey": {
"type": "string",
"nullable": true
}
}
},
"ApplicationInitializeRequestContract": {
"type": "object",
"additionalProperties": false,
"properties": {
"whiteLabelKey": {
"type": "string",
"nullable": true
},
"language": {
"type": "string",
"nullable": true
Expand Down Expand Up @@ -648,6 +656,10 @@
"type": "object",
"additionalProperties": false,
"properties": {
"whiteLabelKey": {
"type": "string",
"nullable": true
},
"userName": {
"type": "string",
"nullable": true
Expand Down Expand Up @@ -699,6 +711,10 @@
"type": "object",
"additionalProperties": false,
"properties": {
"whiteLabelKey": {
"type": "string",
"nullable": true
},
"userName": {
"type": "string",
"nullable": true
Expand Down Expand Up @@ -740,9 +756,6 @@
}
},
"security": [
{
"Bearer": []
},
{
"Bearer": []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<IsPackable>true</IsPackable>
<Version>0.0.0.5</Version>
<Version>0.0.0.6</Version>
<Description>client generated code.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>microservice,Identity,Identity,client</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace EasyMicroservices.IdentityMicroservice.Contracts.Common
{
public class UserSummaryContract
{
public string WhiteLabelKey { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public class AddUserRequestContract
{
public string UserName { get; set; }
public string Password { get; set; }
public string WhiteLabelKey { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace EasyMicroservices.IdentityMicroservice.Contracts.Common
{
public class ApplicationInitializeRequestContract
{
public string WhiteLabelKey { get; set; }
public string Language { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.ContentsMicroservice.Clients" Version="0.0.0.19" />
<PackageReference Include="EasyMicroservices.Cores.AspEntityFrameworkCoreApi" Version="0.0.0.63" />
<PackageReference Include="EasyMicroservices.Logger" Version="0.0.0.5" />
<PackageReference Include="EasyMicroservices.Cores.AspEntityFrameworkCoreApi" Version="0.0.0.79" />
<PackageReference Include="EasyMicroservices.Logger" Version="0.0.0.6" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ItemGroup>
<PackageReference Include="EasyMicroservices.Mapper.CompileTimeMapper" Version="0.0.0.6" />
<PackageReference Include="EasyMicroservices.Mapper.SerializerMapper" Version="0.0.0.3" />
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="0.0.0.8" />
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="0.0.0.9" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using WhiteLables.GeneratedServices;

namespace EasyMicroservices.IdentityMicroservice.Helpers
{
Expand Down Expand Up @@ -41,10 +43,12 @@ public ClaimManager GetClaimManager()
{
return _service.GetService<ClaimManager>();
}

static List<ServiceAddressInfo> ServiceAddresses;
string GetValue(string key)
{
return GetConfiguration().GetValue<string>(key);
if (ServiceAddresses == null)
ServiceAddresses = GetConfiguration().GetSection("ServiceAddresses").Get<List<ServiceAddressInfo>>();
return ServiceAddresses.FirstOrDefault(x => x.Name.Equals(key, StringComparison.OrdinalIgnoreCase)).Address;
}

public IHttpContextAccessor GetHttpContextAccessor()
Expand All @@ -64,27 +68,32 @@ T InternalLogin<T>(T client)

public LanguageClient GetLanguageClient()
{
return InternalLogin(new LanguageClient(GetValue("RootAddresses:Contents"), CurrentHttpClient));
return InternalLogin(new LanguageClient(GetValue("Content"), CurrentHttpClient));
}

public UserClient GetUserClient()
{
return InternalLogin(new UserClient(GetValue("RootAddresses:Authentications"), CurrentHttpClient));
return InternalLogin(new UserClient(GetValue("Authentication"), CurrentHttpClient));
}

public RoleClient GetRoleClient()
{
return InternalLogin(new RoleClient(GetValue("RootAddresses:Authentications"), CurrentHttpClient));
return InternalLogin(new RoleClient(GetValue("Authentication"), CurrentHttpClient));
}

public PersonalAccessTokenClient GetPersonalAccessTokenClientClient()
{
return InternalLogin(new PersonalAccessTokenClient(GetValue("RootAddresses:Authentications"), CurrentHttpClient));
return InternalLogin(new PersonalAccessTokenClient(GetValue("Authentication"), CurrentHttpClient));
}

public ILoggerProvider GetLogger()
{
return ServiceProvider.GetService<ILoggerProvider>();
}

public WhiteLabelClient GetWhiteLabelClient()
{
return InternalLogin(new WhiteLabelClient(GetValue("WhiteLabel"), CurrentHttpClient));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Authentications.GeneratedServices;
using EasyMicroservices.Cores.Interfaces;
using EasyMicroservices.IdentityMicroservice.Contracts.Common;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
Expand Down Expand Up @@ -116,7 +117,7 @@ public List<ClaimContract> SetUniqueIdentity(string value, List<ClaimContract> c
if (value != null)
claims.Add(new ClaimContract
{
Name = "UniqueIdentity",
Name = nameof(IUniqueIdentitySchema.UniqueIdentity),
Value = value
});
return claims;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Authentications.GeneratedServices;
using EasyMicroservices.IdentityMicroservice.Contracts.Common;
using EasyMicroservices.IdentityMicroservice.Contracts.Common;
using EasyMicroservices.IdentityMicroservice.Contracts.Responses;
using EasyMicroservices.IdentityMicroservice.Interfaces;
using EasyMicroservices.ServiceContracts;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using FailedReasonType = EasyMicroservices.ServiceContracts.FailedReasonType;

namespace EasyMicroservices.IdentityMicroservice.Helpers
{
Expand All @@ -24,31 +23,46 @@ public IdentityHelper(IAppUnitOfWork appUnitOfWork)

public async Task<MessageContract<RegisterResponseContract>> Register(Contracts.Requests.AddUserRequestContract request)
{
var client = _appUnitOfWork.GetUserClient();
var usersRecords = await client.GetUserByUserNameAsync(new GetUserByUserNameRequestContract
var whiteLabelClient = _appUnitOfWork.GetWhiteLabelClient();
var uniqueIdentityOfBusiness = await whiteLabelClient.GetUniqueIdentityByKeyAsync(new WhiteLables.GeneratedServices.GuidGetByIdRequestContract()
{
Username = request.UserName.ToLower()
Id = System.Guid.Parse(request.WhiteLabelKey)
}).AsCheckedResult(x => x.Result);

var user = await client.AddAsync(new AddUserRequestContract
var client = _appUnitOfWork.GetUserClient();
var user = await client.GetUserByUserNameAsync(new Authentications.GeneratedServices.GetUserByUserNameRequestContract
{
UserName = request.UserName,
Password = request.Password
UserName = request.UserName.ToLower(),
UniqueIdentity = uniqueIdentityOfBusiness
});
if (user.IsSuccess)
return (FailedReasonType.Duplicate, $"User with UserName: {request.UserName} already exists!");
var addedUserId = await client.AddAsync(new Authentications.GeneratedServices.AddUserRequestContract
{
UserName = request.UserName,
Password = request.Password,
UniqueIdentity = uniqueIdentityOfBusiness
}).AsCheckedResult(x => x.Result);

return new RegisterResponseContract
{
UserId = user.Result,
UserId = addedUserId,
};
}

public virtual async Task<LoginResponseContract> Login(Contracts.Common.UserSummaryContract cred)
public virtual async Task<LoginResponseContract> Login(Contracts.Common.UserSummaryContract request)
{
var _whiteLabelClient = _appUnitOfWork.GetWhiteLabelClient();
var uniqueIdentity = await _whiteLabelClient.GetUniqueIdentityByKeyAsync(new WhiteLables.GeneratedServices.GuidGetByIdRequestContract
{
Id = Guid.Parse(request.WhiteLabelKey)
}).AsCheckedResult(x => x.Result);
var client = _appUnitOfWork.GetUserClient();
var user = await client.VerifyUserIdentityAsync(new Authentications.GeneratedServices.UserSummaryContract
{
UserName = cred.UserName,
Password = cred.Password
UserName = request.UserName,
Password = request.Password,
UniqueIdentity = uniqueIdentity
}).AsCheckedResult(x => x.Result);


Expand All @@ -71,9 +85,10 @@ public async Task<string> GetFullAccessPersonalAccessToken(string personalAccess
Value = personalAccessToken
}).AsCheckedResult(x => x.Result);

var roles = await _appUnitOfWork.GetRoleClient().GetRolesByUserIdAsync(new Authentications.GeneratedServices.Int64GetIdRequestContract
var roles = await _appUnitOfWork.GetRoleClient().GetRolesByUserIdAsync(new Authentications.GeneratedServices.GetByIdAndUniqueIdentityRequestContract
{
Id = user.Id
Id = user.Id,
//UniqueIdentity = user.UniqueIdentity
}).AsCheckedResult(x => x.Result);

List<ClaimContract> claims = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
public JWTManager(IConfiguration config)
{
_config = config;
_authRoot = _config.GetValue<string>("RootAddresses:Authentications");
_authRoot = _config.GetValue<string>("RootAddresses:Authentication");
_userClient = new(_authRoot, new System.Net.Http.HttpClient());
}

public async Task<MessageContract<UserResponseContract>> GenerateTokenWithClaims(List<ClaimContract> claims)

Check warning on line 33 in src/CSharp/EasyMicroservices.IdentityMicroservice.Logics/Helpers/JWTManager.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 33 in src/CSharp/EasyMicroservices.IdentityMicroservice.Logics/Helpers/JWTManager.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 33 in src/CSharp/EasyMicroservices.IdentityMicroservice.Logics/Helpers/JWTManager.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 33 in src/CSharp/EasyMicroservices.IdentityMicroservice.Logics/Helpers/JWTManager.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 33 in src/CSharp/EasyMicroservices.IdentityMicroservice.Logics/Helpers/JWTManager.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 33 in src/CSharp/EasyMicroservices.IdentityMicroservice.Logics/Helpers/JWTManager.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
var tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.UTF8.GetBytes(_config.GetValue<string>("Authorization:JWT:Key"));
Expand Down Expand Up @@ -85,7 +85,7 @@
}


public async Task<ListMessageContract<ClaimContract>> GetClaimsFromToken(string token)

Check warning on line 88 in src/CSharp/EasyMicroservices.IdentityMicroservice.Logics/Helpers/JWTManager.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 88 in src/CSharp/EasyMicroservices.IdentityMicroservice.Logics/Helpers/JWTManager.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 88 in src/CSharp/EasyMicroservices.IdentityMicroservice.Logics/Helpers/JWTManager.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 88 in src/CSharp/EasyMicroservices.IdentityMicroservice.Logics/Helpers/JWTManager.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 88 in src/CSharp/EasyMicroservices.IdentityMicroservice.Logics/Helpers/JWTManager.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 88 in src/CSharp/EasyMicroservices.IdentityMicroservice.Logics/Helpers/JWTManager.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler();
JwtSecurityToken securityToken = (JwtSecurityToken)tokenHandler.ReadToken(token);
Expand Down
Loading
Loading