Skip to content

Commit

Permalink
AuthenticateAsync returns AuthResult when is successful
Browse files Browse the repository at this point in the history
  • Loading branch information
panosru committed Jan 4, 2024
1 parent 7cb3e6a commit 28be1cb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
4 changes: 0 additions & 4 deletions Domains/Account/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,4 @@
<ProjectReference Include="..\..\Shared\Core\Core.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Identity" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions Domains/Account/Core/Identity/Dto/AuthResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace CleanDDDArchitecture.Domains.Account.Core.Identity.Dto;

/// <summary>
/// Represents the result of an authentication operation.
/// </summary>
public class AuthResult
{
/// <summary>
/// Gets or sets the token type.
/// Typically "Bearer" in OAuth2.
/// </summary>
public string TokenType { get; set; }

/// <summary>
/// Gets or sets the serialized access token.
/// This token is used for authenticating subsequent requests.
/// </summary>
public string AccessToken { get; set; }

/// <summary>
/// Gets or sets the number of seconds until the access token expires.
/// This is typically used by clients to know when to refresh the token.
/// </summary>
public long ExpiresIn { get; set; }

/// <summary>
/// Gets or sets the serialized refresh token.
/// This token is used to obtain a new access token once the current one expires.
/// </summary>
public string RefreshToken { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Aviant.Core.Timing;
using CleanDDDArchitecture.Domains.Account.Application.Identity;
using CleanDDDArchitecture.Domains.Account.Core;
using CleanDDDArchitecture.Domains.Account.Core.Identity.Dto;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
Expand Down Expand Up @@ -78,12 +79,12 @@ internal Authenticator(
// Update last accessed date
await UpdateLastAccessedAsync(user);

return new
return new AuthResult
{
token_type = "Bearer",
access_token = accessTokenSerialised,
expires_in = accessToken.ValidTo.ToUnixTimestamp() - Clock.Now.ToUnixTimestamp(),
refresh_token = refreshTokenSerialised
TokenType = "Bearer",
AccessToken = accessTokenSerialised,
ExpiresIn = (long)(accessToken.ValidTo.ToUnixTimestamp() - Clock.Now.ToUnixTimestamp()),
RefreshToken = refreshTokenSerialised
};
}

Expand Down

0 comments on commit 28be1cb

Please sign in to comment.