-
Notifications
You must be signed in to change notification settings - Fork 9.8k
/
WsFederationOptions.cs
187 lines (164 loc) · 7.84 KB
/
WsFederationOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IdentityModel.Tokens.Jwt;
using Microsoft.AspNetCore.Http;
using Microsoft.IdentityModel.Protocols;
using Microsoft.IdentityModel.Protocols.WsFederation;
using Microsoft.IdentityModel.Tokens;
using Microsoft.IdentityModel.Tokens.Saml;
using Microsoft.IdentityModel.Tokens.Saml2;
namespace Microsoft.AspNetCore.Authentication.WsFederation
{
/// <summary>
/// Configuration options for <see cref="WsFederationHandler"/>
/// </summary>
public class WsFederationOptions : RemoteAuthenticationOptions
{
private ICollection<ISecurityTokenValidator> _securityTokenHandlers = new Collection<ISecurityTokenValidator>()
{
new Saml2SecurityTokenHandler(),
new SamlSecurityTokenHandler(),
new JwtSecurityTokenHandler()
};
private TokenValidationParameters _tokenValidationParameters = new TokenValidationParameters();
/// <summary>
/// Initializes a new <see cref="WsFederationOptions"/>
/// </summary>
public WsFederationOptions()
{
CallbackPath = "/signin-wsfed";
// In ADFS the cleanup messages are sent to the same callback path as the initial login.
// In AAD it sends the cleanup message to a random Reply Url and there's no deterministic way to configure it.
// If you manage to get it configured, then you can set RemoteSignOutPath accordingly.
RemoteSignOutPath = "/signin-wsfed";
Events = new WsFederationEvents();
}
/// <summary>
/// Check that the options are valid. Should throw an exception if things are not ok.
/// </summary>
public override void Validate()
{
base.Validate();
if (ConfigurationManager == null)
{
throw new InvalidOperationException($"Provide {nameof(MetadataAddress)}, "
+ $"{nameof(Configuration)}, or {nameof(ConfigurationManager)} to {nameof(WsFederationOptions)}");
}
}
/// <summary>
/// Configuration provided directly by the developer. If provided, then MetadataAddress and the Backchannel properties
/// will not be used. This information should not be updated during request processing.
/// </summary>
public WsFederationConfiguration Configuration { get; set; }
/// <summary>
/// Gets or sets the address to retrieve the wsFederation metadata
/// </summary>
public string MetadataAddress { get; set; }
/// <summary>
/// Responsible for retrieving, caching, and refreshing the configuration from metadata.
/// If not provided, then one will be created using the MetadataAddress and Backchannel properties.
/// </summary>
public IConfigurationManager<WsFederationConfiguration> ConfigurationManager { get; set; }
/// <summary>
/// Gets or sets if a metadata refresh should be attempted after a SecurityTokenSignatureKeyNotFoundException. This allows for automatic
/// recovery in the event of a signature key rollover. This is enabled by default.
/// </summary>
public bool RefreshOnIssuerKeyNotFound { get; set; } = true;
/// <summary>
/// Indicates if requests to the CallbackPath may also be for other components. If enabled the handler will pass
/// requests through that do not contain WsFederation authentication responses. Disabling this and setting the
/// CallbackPath to a dedicated endpoint may provide better error handling.
/// This is disabled by default.
/// </summary>
public bool SkipUnrecognizedRequests { get; set; }
/// <summary>
/// Gets or sets the <see cref="WsFederationEvents"/> to call when processing WsFederation messages.
/// </summary>
public new WsFederationEvents Events
{
get => (WsFederationEvents)base.Events;
set => base.Events = value;
}
/// <summary>
/// Gets or sets the collection of <see cref="ISecurityTokenValidator"/> used to read and validate the <see cref="SecurityToken"/>s.
/// </summary>
public ICollection<ISecurityTokenValidator> SecurityTokenHandlers
{
get
{
return _securityTokenHandlers;
}
set
{
_securityTokenHandlers = value ?? throw new ArgumentNullException(nameof(SecurityTokenHandlers));
}
}
/// <summary>
/// Gets or sets the type used to secure data handled by the middleware.
/// </summary>
public ISecureDataFormat<AuthenticationProperties> StateDataFormat { get; set; }
/// <summary>
/// Gets or sets the <see cref="TokenValidationParameters"/>
/// </summary>
/// <exception cref="ArgumentNullException"> if 'TokenValidationParameters' is null.</exception>
public TokenValidationParameters TokenValidationParameters
{
get
{
return _tokenValidationParameters;
}
set
{
_tokenValidationParameters = value ?? throw new ArgumentNullException(nameof(TokenValidationParameters));
}
}
/// <summary>
/// Gets or sets the 'wreply'. CallbackPath must be set to match or cleared so it can be generated dynamically.
/// This field is optional. If not set then it will be generated from the current request and the CallbackPath.
/// </summary>
public string Wreply { get; set; }
/// <summary>
/// Gets or sets the 'wreply' value used during sign-out.
/// If none is specified then the value from the Wreply field is used.
/// </summary>
public string SignOutWreply { get; set; }
/// <summary>
/// Gets or sets the 'wtrealm'.
/// </summary>
public string Wtrealm { get; set; }
/// <summary>
/// Indicates that the authentication session lifetime (e.g. cookies) should match that of the authentication token.
/// If the token does not provide lifetime information then normal session lifetimes will be used.
/// This is enabled by default.
/// </summary>
public bool UseTokenLifetime { get; set; } = true;
/// <summary>
/// Gets or sets if HTTPS is required for the metadata address or authority.
/// The default is true. This should be disabled only in development environments.
/// </summary>
public bool RequireHttpsMetadata { get; set; } = true;
/// <summary>
/// The Ws-Federation protocol allows the user to initiate logins without contacting the application for a Challenge first.
/// However, that flow is susceptible to XSRF and other attacks so it is disabled here by default.
/// </summary>
public bool AllowUnsolicitedLogins { get; set; }
/// <summary>
/// Requests received on this path will cause the handler to invoke SignOut using the SignOutScheme.
/// </summary>
public PathString RemoteSignOutPath { get; set; }
/// <summary>
/// The Authentication Scheme to use with SignOutAsync from RemoteSignOutPath. SignInScheme will be used if this
/// is not set.
/// </summary>
public string SignOutScheme { get; set; }
/// <summary>
/// SaveTokens is not supported in WsFederation
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public new bool SaveTokens { get; set; }
}
}