1
1
using Ocelot . Configuration . File ;
2
- using System . Collections . Generic ;
3
2
4
3
namespace Ocelot . Configuration
5
4
{
6
5
public sealed class AuthenticationOptions
7
6
{
8
- public AuthenticationOptions ( List < string > allowedScopes , List < string > requiredRole , string authenticationProviderKey , string scopeKey , string roleKey , string policyName )
9
- {
10
- PolicyName = policyName ;
11
- AllowedScopes = allowedScopes ;
12
- RequiredRole = requiredRole ;
13
- AuthenticationProviderKey = authenticationProviderKey ;
14
- AuthenticationProviderKeys = [ ] ;
15
- }
16
-
17
7
public AuthenticationOptions ( FileAuthenticationOptions from )
18
8
{
19
9
AllowedScopes = from . AllowedScopes ?? [ ] ;
20
- AuthenticationProviderKey = from . AuthenticationProviderKey ?? string . Empty ;
21
- AuthenticationProviderKeys = from . AuthenticationProviderKeys ?? [ ] ;
10
+ BuildAuthenticationProviderKeys ( from . AuthenticationProviderKey , from . AuthenticationProviderKeys ) ;
11
+ PolicyName = from . PolicyName ;
12
+ RequiredRole = from . RequiredRole ;
13
+ ScopeKey = from . ScopeKey ;
14
+ RoleKey = from . RoleKey ;
22
15
}
23
16
24
- public AuthenticationOptions ( List < string > allowedScopes , string authenticationProviderKey ,
25
- string [ ] authenticationProviderKeys )
17
+ public AuthenticationOptions ( List < string > allowedScopes , string authenticationProviderKey , string [ ] authenticationProviderKeys )
26
18
{
27
19
AllowedScopes = allowedScopes ?? [ ] ;
28
- AuthenticationProviderKey = authenticationProviderKey ?? string . Empty ;
29
- AuthenticationProviderKeys = authenticationProviderKeys ?? [ ] ;
20
+ BuildAuthenticationProviderKeys ( authenticationProviderKey , authenticationProviderKeys ) ;
30
21
}
31
22
32
- public AuthenticationOptions ( List < string > allowedScopes , List < string > requiredRole , string authenticationProviderKey , string scopeKey , string roleKey , string policyName )
23
+ public AuthenticationOptions ( List < string > allowedScopes , string [ ] authenticationProviderKeys , List < string > requiredRole , string scopeKey , string roleKey , string policyName )
33
24
{
34
- PolicyName = policyName ;
35
25
AllowedScopes = allowedScopes ;
26
+ AuthenticationProviderKey = string . Empty ;
27
+ AuthenticationProviderKeys = authenticationProviderKeys ?? [ ] ;
28
+ PolicyName = policyName ;
36
29
RequiredRole = requiredRole ;
37
- AuthenticationProviderKey = authenticationProviderKey ;
38
30
ScopeKey = scopeKey ;
39
31
RoleKey = roleKey ;
40
32
}
41
33
34
+ /// <summary>
35
+ /// Builds auth keys migrating legacy key to new ones.
36
+ /// </summary>
37
+ /// <param name="legacyKey">The legacy <see cref="AuthenticationProviderKey"/>.</param>
38
+ /// <param name="keys">New <see cref="AuthenticationProviderKeys"/> to build.</param>
39
+ private void BuildAuthenticationProviderKeys ( string legacyKey , string [ ] keys )
40
+ {
41
+ keys ??= [ ] ;
42
+ if ( string . IsNullOrEmpty ( legacyKey ) )
43
+ {
44
+ return ;
45
+ }
46
+
47
+ // Add legacy Key to new Keys array as the first element
48
+ var arr = new string [ keys . Length + 1 ] ;
49
+ arr [ 0 ] = legacyKey ;
50
+ Array . Copy ( keys , 0 , arr , 1 , keys . Length ) ;
51
+
52
+ // Update the object
53
+ AuthenticationProviderKeys = arr ;
54
+ AuthenticationProviderKey = string . Empty ;
55
+ }
56
+
42
57
public List < string > AllowedScopes { get ; }
43
58
44
59
/// <summary>
@@ -48,7 +63,7 @@ public AuthenticationOptions(List<string> allowedScopes, List<string> requiredRo
48
63
/// A <see langword="string"/> value of the scheme name.
49
64
/// </value>
50
65
[ Obsolete ( "Use the " + nameof ( AuthenticationProviderKeys ) + " property!" ) ]
51
- public string AuthenticationProviderKey { get ; }
66
+ public string AuthenticationProviderKey { get ; private set ; }
52
67
53
68
/// <summary>
54
69
/// Multiple authentication schemes registered in DI services with appropriate authentication providers.
@@ -59,7 +74,7 @@ public AuthenticationOptions(List<string> allowedScopes, List<string> requiredRo
59
74
/// <value>
60
75
/// An array of <see langword="string"/> values of the scheme names.
61
76
/// </value>
62
- public string [ ] AuthenticationProviderKeys { get ; }
77
+ public string [ ] AuthenticationProviderKeys { get ; private set ; }
63
78
64
79
public List < string > RequiredRole { get ; }
65
80
public string ScopeKey { get ; }
0 commit comments