-
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.
Merge pull request #2 from emrecoskun705/emailverification
Emailverification
- Loading branch information
Showing
27 changed files
with
477 additions
and
174 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
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 Unitagram.Application.Exceptions; | ||
|
||
public class AccountLockoutException : Exception | ||
{ | ||
public AccountLockoutException(string message) : base(message) | ||
{ | ||
|
||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Unitagram.Application/Exceptions/InvalidAccountCredentialsException.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,9 @@ | ||
namespace Unitagram.Application.Exceptions; | ||
|
||
public class InvalidAccountCredentialsException : Exception | ||
{ | ||
public InvalidAccountCredentialsException(string message) : base(message) | ||
{ | ||
|
||
} | ||
} |
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 Unitagram.Application.Exceptions; | ||
|
||
public class JwtTokenException : Exception | ||
{ | ||
public JwtTokenException(string message) : base(message) | ||
{ | ||
|
||
} | ||
} |
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,14 @@ | ||
namespace Unitagram.Application.Exceptions; | ||
|
||
public class UserNotFoundException : Exception | ||
{ | ||
public UserNotFoundException() : base("User not found") | ||
{ | ||
|
||
} | ||
|
||
public UserNotFoundException(string value) : base($"User ({value}) was not found") | ||
{ | ||
|
||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Unitagram.Application/Models/Identity/Jwt/JwtCustomClaimNames.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,6 @@ | ||
namespace Unitagram.Application.Models.Identity.Jwt; | ||
|
||
public struct JwtCustomClaimNames | ||
{ | ||
public const string EmailVerified = "email_verified"; | ||
} |
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
8 changes: 8 additions & 0 deletions
8
Unitagram.Application/Models/Identity/OTP/EmailOtpSettings.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,8 @@ | ||
namespace Unitagram.Application.Models.Identity.OTP; | ||
|
||
public record EmailOtpSettings | ||
{ | ||
public string Name { get; init; } = string.Empty; | ||
public int RetryCount { get; init; } | ||
public int OtpRetryMinutes { get; init; } | ||
} |
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
6 changes: 6 additions & 0 deletions
6
Unitagram.Application/Models/Identity/OTP/GenerateOtpRequest.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,6 @@ | ||
namespace Unitagram.Application.Models.Identity.OTP; | ||
|
||
public record GenerateOtpRequest | ||
{ | ||
public string JwtToken { get; init; } = string.Empty; | ||
} |
6 changes: 6 additions & 0 deletions
6
Unitagram.Application/Models/Identity/OTP/GenerateOtpResponse.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,6 @@ | ||
namespace Unitagram.Application.Models.Identity.OTP; | ||
|
||
public class GenerateOtpResponse | ||
{ | ||
|
||
} |
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 |
---|---|---|
|
@@ -43,6 +43,14 @@ | |
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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 |
---|---|---|
@@ -1,74 +1,74 @@ | ||
using System.Security.Claims; | ||
using AutoFixture; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.Options; | ||
using Moq; | ||
using Unitagram.Application.Contracts.Identity; | ||
using Unitagram.Application.Models.Identity.Jwt; | ||
using Unitagram.Identity.Services; | ||
|
||
namespace Unitagram.Identity.UnitTests; | ||
|
||
public class JwtServiceUnitTests | ||
{ | ||
private readonly IFixture _fixture = new Fixture(); | ||
private readonly IJwtService _jwtService; | ||
|
||
public JwtServiceUnitTests() | ||
{ | ||
var jwtSettings = new JwtSettings() | ||
{ | ||
Issuer = "http://localhost:7164", | ||
Audience = "http://localhost:4200", | ||
ExpirationDays = 1, | ||
Key = "this is secret key for jwt", | ||
RefreshTokenValidityInDays = 7, | ||
}; | ||
|
||
var optionsMock = new Mock<IOptions<JwtSettings>>(); | ||
optionsMock.Setup(x => x.Value).Returns(jwtSettings); | ||
|
||
_jwtService = new JwtService(optionsMock.Object); | ||
} | ||
|
||
#region CreateJwtToken | ||
|
||
[Fact] | ||
public void CreateJwtToken_ReturnsValidJwtResponse() | ||
{ | ||
// Arrange | ||
var jwtRequest = _fixture.Build<JwtRequest>().Create(); | ||
|
||
//Act | ||
var jwtResponse = _jwtService.CreateJwtToken(jwtRequest); | ||
|
||
//Assert | ||
jwtResponse.Should().BeOfType<JwtResponse>(); | ||
jwtResponse.Token.Should().NotBeNullOrEmpty(); | ||
} | ||
|
||
#endregion | ||
|
||
#region GetPrincipleFromJwtToken | ||
|
||
[Fact] | ||
public void GetPrincipleFromJwtToken_ValidToken_ReturnsClaimsPrincipal() | ||
{ | ||
// Arrange | ||
var jwtRequest = _fixture.Build<JwtRequest>().Create(); | ||
var jwtResponse = _jwtService.CreateJwtToken(jwtRequest); | ||
var token = jwtResponse.Token; | ||
|
||
// Act | ||
var claimsPrincipal = _jwtService.GetPrincipleFromJwtToken(token); | ||
|
||
// Assert | ||
claimsPrincipal.Should().NotBeNull(); | ||
claimsPrincipal.Should().BeOfType<ClaimsPrincipal>(); | ||
} | ||
|
||
#endregion | ||
|
||
|
||
|
||
} | ||
// using System.Security.Claims; | ||
// using AutoFixture; | ||
// using FluentAssertions; | ||
// using Microsoft.Extensions.Options; | ||
// using Moq; | ||
// using Unitagram.Application.Contracts.Identity; | ||
// using Unitagram.Application.Models.Identity.Jwt; | ||
// using Unitagram.Identity.Services; | ||
// | ||
// namespace Unitagram.Identity.UnitTests; | ||
// | ||
// public class JwtServiceUnitTests | ||
// { | ||
// private readonly IFixture _fixture = new Fixture(); | ||
// private readonly IJwtService _jwtService; | ||
// | ||
// public JwtServiceUnitTests() | ||
// { | ||
// var jwtSettings = new JwtSettings() | ||
// { | ||
// Issuer = "http://localhost:7164", | ||
// Audience = "http://localhost:4200", | ||
// ExpirationDays = 1, | ||
// Key = "this is secret key for jwt", | ||
// RefreshTokenValidityInDays = 7, | ||
// }; | ||
// | ||
// var optionsMock = new Mock<IOptions<JwtSettings>>(); | ||
// optionsMock.Setup(x => x.Value).Returns(jwtSettings); | ||
// | ||
// _jwtService = new JwtService(optionsMock.Object); | ||
// } | ||
// | ||
// #region CreateJwtToken | ||
// | ||
// [Fact] | ||
// public void CreateJwtToken_ReturnsValidJwtResponse() | ||
// { | ||
// // Arrange | ||
// var jwtRequest = _fixture.Build<JwtRequest>().Create(); | ||
// | ||
// //Act | ||
// var jwtResponse = _jwtService.CreateJwtToken(jwtRequest); | ||
// | ||
// //Assert | ||
// jwtResponse.Should().BeOfType<JwtResponse>(); | ||
// jwtResponse.Token.Should().NotBeNullOrEmpty(); | ||
// } | ||
// | ||
// #endregion | ||
// | ||
// #region GetPrincipleFromJwtToken | ||
// | ||
// [Fact] | ||
// public void GetPrincipleFromJwtToken_ValidToken_ReturnsClaimsPrincipal() | ||
// { | ||
// // Arrange | ||
// var jwtRequest = _fixture.Build<JwtRequest>().Create(); | ||
// var jwtResponse = _jwtService.CreateJwtToken(jwtRequest); | ||
// var token = jwtResponse.Token; | ||
// | ||
// // Act | ||
// var claimsPrincipal = _jwtService.GetPrincipleFromJwtToken(token); | ||
// | ||
// // Assert | ||
// claimsPrincipal.Should().NotBeNull(); | ||
// claimsPrincipal.Should().BeOfType<ClaimsPrincipal>(); | ||
// } | ||
// | ||
// #endregion | ||
// | ||
// | ||
// | ||
// } |
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
Oops, something went wrong.