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