11
11
12
12
namespace Medidata . MAuth . Core
13
13
{
14
- internal class MAuthAuthenticator
14
+ /// <summary>
15
+ /// MAuth service class to process authentication.
16
+ /// </summary>
17
+ public class MAuthAuthenticator : IMAuthAuthenticator
15
18
{
16
19
private const int AllowedDriftSeconds = 300 ;
17
20
private static readonly TimeSpan AllowedDriftTimeSpan = TimeSpan . FromSeconds ( AllowedDriftSeconds ) ;
@@ -22,8 +25,17 @@ internal class MAuthAuthenticator
22
25
private readonly IDateTimeOffsetWrapper _dateTimeOffsetWrapper ;
23
26
private readonly Lazy < HttpClient > _lazyHttpClient ;
24
27
28
+ /// <summary>
29
+ /// MAuth application uuid.
30
+ /// </summary>
25
31
public Guid ApplicationUuid => _options . ApplicationUuid ;
26
32
33
+ /// <summary>
34
+ /// Create a new instance <see cref="MAuthAuthenticator"/>
35
+ /// </summary>
36
+ /// <param name="options">MAuth options</param>
37
+ /// <param name="logger">Logger</param>
38
+ /// <param name="cacheService">Cache service. (Optional)</param>
27
39
public MAuthAuthenticator ( MAuthOptionsBase options , ILogger logger , ICacheService cacheService = null )
28
40
{
29
41
if ( options . ApplicationUuid == default )
@@ -41,6 +53,36 @@ public MAuthAuthenticator(MAuthOptionsBase options, ILogger logger, ICacheServic
41
53
_lazyHttpClient = new Lazy < HttpClient > ( ( ) => CreateHttpClient ( options ) ) ;
42
54
_dateTimeOffsetWrapper = options . DateTimeOffsetWrapper ;
43
55
}
56
+
57
+ /// <summary>
58
+ /// Create a new instance <see cref="MAuthAuthenticator"/>
59
+ /// </summary>
60
+ /// <param name="options">MAuth options</param>
61
+ /// <param name="logger">Logger</param>
62
+ /// <param name="httpClient">Http Client</param>
63
+ /// <param name="cacheService">Cache service. (Optional)</param>
64
+ public MAuthAuthenticator ( MAuthOptionsBase options , ILogger logger , HttpClient httpClient , ICacheService cacheService = null )
65
+ {
66
+ if ( options . ApplicationUuid == default )
67
+ throw new ArgumentException ( nameof ( options . ApplicationUuid ) ) ;
68
+
69
+ if ( options . MAuthServiceUrl == null )
70
+ throw new ArgumentNullException ( nameof ( options . MAuthServiceUrl ) ) ;
71
+
72
+ if ( string . IsNullOrWhiteSpace ( options . PrivateKey ) )
73
+ throw new ArgumentNullException ( nameof ( options . PrivateKey ) ) ;
74
+
75
+ _cache = cacheService ?? new MemoryCacheService ( new MemoryCache ( new MemoryCacheOptions ( ) ) ) ;
76
+ _options = options ;
77
+ _logger = logger ;
78
+ #if NET6_0_OR_GREATER
79
+ _lazyHttpClient = new Lazy < HttpClient > ( httpClient ) ;
80
+ #else
81
+ _lazyHttpClient = new Lazy < HttpClient > ( ( ) => httpClient ) ;
82
+ #endif
83
+
84
+ _dateTimeOffsetWrapper = options . DateTimeOffsetWrapper ;
85
+ }
44
86
45
87
/// <summary>
46
88
/// Verifies if the <see cref="HttpRequestMessage"/> request is authenticated or not.
0 commit comments