Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 54128e8

Browse files
committed
Add response_mode=query support for OpenID Connect
1 parent ab4ba79 commit 54128e8

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs

+24-2
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,19 @@ protected override async Task<bool> HandleUnauthorizedAsync([NotNull] ChallengeC
139139
// [brentschmaltz] - #215 this should be a property on RedirectToIdentityProviderNotification not on the OIDCMessage.
140140
RequestType = OpenIdConnectRequestType.AuthenticationRequest,
141141
Resource = Options.Resource,
142-
ResponseMode = Options.ResponseMode,
143142
ResponseType = Options.ResponseType,
144143
Scope = Options.Scope
145144
};
146145

146+
// Omitting the response_mode parameter when it already corresponds to the default
147+
// response_mode used for the specified response_type is recommended by the specifications.
148+
// See http://openid.net/specs/oauth-v2-multiple-response-types-1_0.html#ResponseModes
149+
if (!string.Equals(Options.ResponseType, OpenIdConnectResponseTypes.Code, StringComparison.Ordinal) ||
150+
!string.Equals(Options.ResponseMode, OpenIdConnectResponseModes.Query, StringComparison.Ordinal))
151+
{
152+
message.ResponseMode = Options.ResponseMode;
153+
}
154+
147155
if (Options.ProtocolValidator.RequireNonce)
148156
{
149157
message.Nonce = Options.ProtocolValidator.GenerateNonce();
@@ -236,8 +244,22 @@ protected override async Task<AuthenticationTicket> HandleAuthenticateAsync()
236244

237245
OpenIdConnectMessage message = null;
238246

247+
if (string.Equals(Request.Method, "GET", StringComparison.OrdinalIgnoreCase))
248+
{
249+
message = new OpenIdConnectMessage(Request.Query);
250+
251+
// response_mode=query (explicit or not) and a response_type containing id_token
252+
// or token are not considered as a safe combination and MUST be rejected.
253+
// See http://openid.net/specs/oauth-v2-multiple-response-types-1_0.html#Security
254+
if (!string.IsNullOrWhiteSpace(message.IdToken) || !string.IsNullOrWhiteSpace(message.Token))
255+
{
256+
Logger.LogError("An OpenID Connect response cannot contain an identity token " +
257+
"or an access token when using response_mode=query");
258+
return null;
259+
}
260+
}
239261
// assumption: if the ContentType is "application/x-www-form-urlencoded" it should be safe to read as it is small.
240-
if (string.Equals(Request.Method, "POST", StringComparison.OrdinalIgnoreCase)
262+
else if (string.Equals(Request.Method, "POST", StringComparison.OrdinalIgnoreCase)
241263
&& !string.IsNullOrWhiteSpace(Request.ContentType)
242264
// May have media/type; charset=utf-8, allow partial match.
243265
&& Request.ContentType.StartsWith("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase)

src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public OpenIdConnectProtocolValidator ProtocolValidator
239239
/// <summary>
240240
/// Gets or sets the 'response_mode'.
241241
/// </summary>
242-
public string ResponseMode { get; private set; }
242+
public string ResponseMode { get; set; }
243243

244244
/// <summary>
245245
/// Gets or sets the 'response_type'.

0 commit comments

Comments
 (0)