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

Commit ab8a2fb

Browse files
committed
#455 Remove RedirectUri from OIDC, use CallbackPath.
1 parent 0eaec21 commit ab8a2fb

File tree

5 files changed

+5
-35
lines changed

5 files changed

+5
-35
lines changed

samples/OpenIdConnectSample/Startup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
3333
options.ClientId = "63a87a83-64b9-4ac1-b2c5-092126f8474f";
3434
options.ClientSecret = "Yse2iP7tO1Azq0iDajNisMaTSnIDv+FXmAsFuXr+Cy8="; // for code flow
3535
options.Authority = "https://login.windows.net/tratcheroutlook.onmicrosoft.com";
36-
options.RedirectUri = "http://localhost:42023/signin-oidc";
3736
options.ResponseType = OpenIdConnectResponseTypes.Code;
3837
options.GetClaimsFromUserInfoEndpoint = true;
3938
});

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ protected override async Task<bool> HandleUnauthorizedAsync(ChallengeContext con
192192
{
193193
ClientId = Options.ClientId,
194194
IssuerAddress = _configuration?.AuthorizationEndpoint ?? string.Empty,
195-
RedirectUri = Options.RedirectUri,
195+
RedirectUri = BuildRedirectUri(Options.CallbackPath),
196196
Resource = Options.Resource,
197197
ResponseType = Options.ResponseType,
198198
Scope = string.Join(" ", Options.Scope)
@@ -239,18 +239,8 @@ protected override async Task<bool> HandleUnauthorizedAsync(ChallengeContext con
239239
properties.Items[OpenIdConnectDefaults.UserstatePropertiesKey] = message.State;
240240
}
241241

242-
var redirectUriForCode = message.RedirectUri;
243-
if (string.IsNullOrEmpty(redirectUriForCode))
244-
{
245-
Logger.LogDebug(8, "Using Options.RedirectUri for 'redirect_uri': '{0}'.", Options.RedirectUri);
246-
redirectUriForCode = Options.RedirectUri;
247-
}
248-
249-
if (!string.IsNullOrEmpty(redirectUriForCode))
250-
{
251-
// When redeeming a 'code' for an AccessToken, this value is needed
252-
properties.Items.Add(OpenIdConnectDefaults.RedirectUriForCodePropertiesKey, redirectUriForCode);
253-
}
242+
// When redeeming a 'code' for an AccessToken, this value is needed
243+
properties.Items.Add(OpenIdConnectDefaults.RedirectUriForCodePropertiesKey, message.RedirectUri);
254244

255245
message.State = Options.StateDataFormat.Protect(properties);
256246

@@ -957,8 +947,7 @@ private async Task<MessageReceivedContext> RunMessageReceivedEventAsync(OpenIdCo
957947

958948
private async Task<AuthorizationCodeReceivedContext> RunAuthorizationCodeReceivedEventAsync(OpenIdConnectMessage message, AuthenticationProperties properties, AuthenticationTicket ticket, JwtSecurityToken jwt)
959949
{
960-
var redirectUri = properties.Items.ContainsKey(OpenIdConnectDefaults.RedirectUriForCodePropertiesKey) ?
961-
properties.Items[OpenIdConnectDefaults.RedirectUriForCodePropertiesKey] : Options.RedirectUri;
950+
var redirectUri = properties.Items[OpenIdConnectDefaults.RedirectUriForCodePropertiesKey];
962951

963952
Logger.LogDebug(32, "AuthorizationCode received: '{0}'", message.Code);
964953

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,6 @@ public OpenIdConnectMiddleware(
121121
Options.StringDataFormat = new SecureDataFormat<string>(new StringSerializer(), dataProtector);
122122
}
123123

124-
// if the user has not set the AuthorizeCallback, set it from the redirect_uri
125-
if (!Options.CallbackPath.HasValue)
126-
{
127-
Uri redirectUri;
128-
if (!string.IsNullOrEmpty(Options.RedirectUri) && Uri.TryCreate(Options.RedirectUri, UriKind.Absolute, out redirectUri))
129-
{
130-
// Redirect_Uri must be a very specific, case sensitive value, so we can't generate it. Instead we generate AuthorizeCallback from it.
131-
Options.CallbackPath = PathString.FromUriComponent(redirectUri);
132-
}
133-
}
134124

135125
if (Options.Events == null)
136126
{

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,6 @@ public OpenIdConnectOptions(string authenticationScheme)
125125
[SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Logout", Justification = "This is the term used in the spec.")]
126126
public string PostLogoutRedirectUri { get; set; }
127127

128-
/// <summary>
129-
/// Gets or sets the 'redirect_uri'.
130-
/// </summary>
131-
[SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Justification = "By Design")]
132-
public string RedirectUri { get; set; }
133-
134128
/// <summary>
135129
/// Gets or sets if a metadata refresh should be attempted after a SecurityTokenSignatureKeyNotFoundException. This allows for automatic
136130
/// recovery in the event of a signature key rollover. This is enabled by default.

test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ public async Task ChallengeSettingState(string userState, string challenge)
215215
OnRedirectToAuthenticationEndpoint = context =>
216216
{
217217
context.ProtocolMessage.State = userState;
218+
context.ProtocolMessage.RedirectUri = queryValues.RedirectUri;
218219
return Task.FromResult<object>(null);
219220
}
220221

@@ -285,8 +286,6 @@ private void SetOptions(OpenIdConnectOptions options, List<string> parameters, E
285286
{
286287
if (param.Equals(OpenIdConnectParameterNames.ClientId))
287288
options.ClientId = queryValues.ClientId;
288-
else if (param.Equals(OpenIdConnectParameterNames.RedirectUri))
289-
options.RedirectUri = queryValues.RedirectUri;
290289
else if (param.Equals(OpenIdConnectParameterNames.Resource))
291290
options.Resource = queryValues.Resource;
292291
else if (param.Equals(OpenIdConnectParameterNames.Scope)) {
@@ -309,7 +308,6 @@ private List<string> DefaultParameters(string[] additionalParams = null)
309308
new List<string>
310309
{
311310
OpenIdConnectParameterNames.ClientId,
312-
OpenIdConnectParameterNames.RedirectUri,
313311
OpenIdConnectParameterNames.Resource,
314312
OpenIdConnectParameterNames.ResponseMode,
315313
OpenIdConnectParameterNames.Scope,

0 commit comments

Comments
 (0)