Last active
April 19, 2019 17:53
-
-
Save MarneeDear/c954b20416d3c1cadf5b7c359bbc0a00 to your computer and use it in GitHub Desktop.
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
(* | |
Am I doing this right? | |
*) | |
//How to do setup custom DataProtectorTokenProvider options? | |
//The guide talks about how to do this for the email token | |
//https://docs.microsoft.com/en-us/aspnet/core/security/authentication/accconfirm?view=aspnetcore-2.2&tabs=visual-studio#change-the-email-token-lifespan | |
//The C# version from the ASPNET guide linked above | |
public class CustomEmailConfirmationTokenProvider<TUser> | |
: DataProtectorTokenProvider<TUser> where TUser : class | |
{ | |
public CustomEmailConfirmationTokenProvider(IDataProtectionProvider dataProtectionProvider, | |
IOptions<EmailConfirmationTokenProviderOptions> options) | |
: base(dataProtectionProvider, options) | |
{ | |
} | |
} | |
public class EmailConfirmationTokenProviderOptions : DataProtectionTokenProviderOptions | |
{ | |
public EmailConfirmationTokenProviderOptions() | |
{ | |
Name = "EmailDataProtectorTokenProvider"; | |
TokenLifespan = TimeSpan.FromHours(4); | |
} | |
} | |
//My F# version | |
//Generic Constraints in F#: https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/generics/constraints | |
type CustomEmailConfirmationTokenProvider<'TUser when 'TUser : not struct> = | |
inherit DataProtectorTokenProvider<'TUser> | |
new(dataProtectionProvider, options) = { inherit DataProtectorTokenProvider<'TUser>(dataProtectionProvider, options) } | |
type EmailConfirmationTokenProviderOptions = | |
inherit DataProtectionTokenProviderOptions | |
new () = { inherit DataProtectionTokenProviderOptions() } | |
member __.Name = "EmailDataProtectorTokenProvider" | |
member __.TokenLifespan = TimeSpan.FromHours(4.0) | |
//From Phil (cartertmp) in the F# slack | |
open System | |
type DataProtectorTokenProvider<'T>(dpp, options) = class end | |
type DataProtectionTokenProviderOptions() = class end | |
type CustomEmailConfirmationTokenProvider<'TUser when 'TUser : not struct>(dataProtectionProvider, options) = | |
inherit DataProtectorTokenProvider<'TUser>(dataProtectionProvider, options) | |
type EmailConfirmationTokenProviderOptions() = | |
inherit DataProtectionTokenProviderOptions() | |
member __.Name = "EmailDataProtectorTokenProvider" | |
member __.TokenLifespan = TimeSpan.FromHours(4.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment