-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Magic links to the SDK Co-authored-by: Oleksii Holub <[email protected]> Co-authored-by: Jonas Hendrickx <[email protected]>
- Loading branch information
1 parent
1ba094c
commit 79b4b6e
Showing
7 changed files
with
87 additions
and
3 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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Passwordless.Models; | ||
|
||
/// <summary> | ||
|
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,23 @@ | ||
using System; | ||
using Passwordless.Helpers.Extensions; | ||
|
||
namespace Passwordless.Models; | ||
|
||
/// <summary> | ||
/// Request for sending an email with a link that contains a 1-time-use token to be used for validating signin. | ||
/// </summary> | ||
/// <param name="EmailAddress">Valid email address that will be the recipient of the magic link email</param> | ||
/// <param name="UrlTemplate">Url template that needs to contain the token template, <token>. The token template will be replaced with a valid signin token to be sent to the verify sign in token endpoint (https://v4.passwsordless.dev/signin/verify).</param> | ||
/// <param name="UserId">Identifier for the user the email is intended for.</param> | ||
/// <param name="TimeToLive">Length of time the magic link will be active. Default value will be 15 minutes.</param> | ||
public record SendMagicLinkRequest(string EmailAddress, string UrlTemplate, string UserId, TimeSpan? TimeToLive) | ||
{ | ||
internal SendMagicLinkApiRequest ToRequest() => | ||
new( | ||
this.EmailAddress, | ||
this.UrlTemplate, | ||
this.UserId, | ||
this.TimeToLive?.TotalSeconds.Pipe(Convert.ToInt32)); | ||
}; | ||
|
||
internal record SendMagicLinkApiRequest(string EmailAddress, string UrlTemplate, string UserId, int? TimeToLive); |
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 |
---|---|---|
|
@@ -96,7 +96,8 @@ public async Task<PasswordlessApplication> CreateAppAsync() | |
{ | ||
"adminEmail": "[email protected]", | ||
"eventLoggingIsEnabled": true, | ||
"eventLoggingRetentionPeriod": 7 | ||
"eventLoggingRetentionPeriod": 7, | ||
"magicLinkEmailMonthlyQuota" : 100 | ||
} | ||
""", | ||
Encoding.UTF8, | ||
|
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,41 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Passwordless.Models; | ||
using Passwordless.Tests.Infra; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Passwordless.Tests; | ||
|
||
public class MagicLinksTests(TestApiFixture api, ITestOutputHelper testOutput) : ApiTestBase(api, testOutput) | ||
{ | ||
[Fact] | ||
public async Task I_can_send_a_magic_link_with_a_specified_time_to_live() | ||
{ | ||
// Arrange | ||
var passwordless = await Api.CreateClientAsync(); | ||
var request = new SendMagicLinkRequest("[email protected]", "https://www.example.com?token=$TOKEN", "user", new TimeSpan(0, 15, 0)); | ||
|
||
// Act | ||
var action = async () => await passwordless.SendMagicLinkAsync(request, CancellationToken.None); | ||
|
||
// Assert | ||
await action.Should().NotThrowAsync(); | ||
} | ||
|
||
[Fact] | ||
public async Task I_can_send_a_magic_link_without_a_time_to_live() | ||
{ | ||
// Arrange | ||
var passwordless = await Api.CreateClientAsync(); | ||
var request = new SendMagicLinkRequest("[email protected]", "https://www.example.com?token=$TOKEN", "user", null); | ||
|
||
// Act | ||
var action = async () => await passwordless.SendMagicLinkAsync(request, CancellationToken.None); | ||
|
||
// Assert | ||
await action.Should().NotThrowAsync(); | ||
} | ||
} |