-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace MadWorldNL.Clients.Admin.Domain; | ||
|
||
public class AuthenticationToken | ||
{ | ||
public bool IsSuccess { get; init; } | ||
public string AccessToken { get; init; } = string.Empty; | ||
public string RefreshToken { get; init; } = string.Empty; | ||
public DateTime Expires { get; init; } | ||
} |
20 changes: 20 additions & 0 deletions
20
sources/Clients.Admin/Extensions/WebApplicationBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using MadWorldNL.Clients.Admin.Services; | ||
using Server.Presentation.Grpc.Authentication.V1; | ||
|
||
namespace MadWorldNL.Clients.Admin.Extensions; | ||
|
||
public static class WebApplicationBuilderExtensions | ||
{ | ||
public static void AddGrpcClients(this WebApplicationBuilder builder) | ||
{ | ||
builder.Services.AddGrpcClient<Authentication.AuthenticationClient>(o => | ||
{ | ||
o.Address = new Uri("https://localhost:5001"); // Replace with your gRPC service's address | ||
}); | ||
} | ||
|
||
public static void AddAdminServices(this WebApplicationBuilder builder) | ||
{ | ||
builder.Services.AddScoped<IAuthenticationService, AuthenticationService>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using MadWorldNL.Clients.Admin.Domain; | ||
using Server.Presentation.Grpc.Authentication.V1; | ||
|
||
namespace MadWorldNL.Clients.Admin.Services; | ||
|
||
public class AuthenticationService : IAuthenticationService | ||
{ | ||
private readonly Authentication.AuthenticationClient _client; | ||
|
||
public AuthenticationService(Authentication.AuthenticationClient client) | ||
{ | ||
_client = client; | ||
} | ||
|
||
public AuthenticationToken Login(string username, string password, string audience) | ||
{ | ||
var request = new LoginRequest() | ||
{ | ||
Username = username, | ||
Password = password, | ||
Audience = audience | ||
}; | ||
|
||
var response = _client.Login(request); | ||
|
||
return new AuthenticationToken() | ||
{ | ||
IsSuccess = response.IsSuccess, | ||
AccessToken = response.AccessToken, | ||
RefreshToken = response.RefreshToken, | ||
Expires = response.Expiration.ToDateTime() | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using MadWorldNL.Clients.Admin.Domain; | ||
|
||
namespace MadWorldNL.Clients.Admin.Services; | ||
|
||
public interface IAuthenticationService | ||
{ | ||
AuthenticationToken Login(string username, string password, string audience); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters