Browse Source

Backport the metadata endpoint changes to OpenIddict 1.x

pull/670/head
Kévin Chalet 9 years ago
parent
commit
3e16da7190
  1. 5
      src/OpenIddict.Abstractions/OpenIddictConstants.cs
  2. 7
      src/OpenIddict.Server/Internal/OpenIddictServerProvider.Discovery.cs
  3. 22
      test/OpenIddict.Server.Tests/Internal/OpenIddictServerProviderTests.Discovery.cs
  4. 19
      test/OpenIddict.Server.Tests/Internal/OpenIddictServerProviderTests.cs
  5. 3
      test/OpenIddict.Server.Tests/OpenIddict.Server.Tests.csproj

5
src/OpenIddict.Abstractions/OpenIddictConstants.cs

@ -39,11 +39,6 @@ namespace OpenIddict.Abstractions
public const string LogoutRequest = "openiddict-logout-request:"; public const string LogoutRequest = "openiddict-logout-request:";
} }
public static class Metadata
{
public const string ExternalProvidersSupported = "external_providers_supported";
}
public static class Permissions public static class Permissions
{ {
public static class Endpoints public static class Endpoints

7
src/OpenIddict.Server/Internal/OpenIddictServerProvider.Discovery.cs

@ -4,13 +4,11 @@
* the license and the contributors participating to this project. * the license and the contributors participating to this project.
*/ */
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using AspNet.Security.OpenIdConnect.Primitives; using AspNet.Security.OpenIdConnect.Primitives;
using AspNet.Security.OpenIdConnect.Server; using AspNet.Security.OpenIdConnect.Server;
using JetBrains.Annotations; using JetBrains.Annotations;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using OpenIddict.Abstractions;
namespace OpenIddict.Server namespace OpenIddict.Server
{ {
@ -47,11 +45,6 @@ namespace OpenIddict.Server
context.Metadata[OpenIdConnectConstants.Metadata.RequestParameterSupported] = false; context.Metadata[OpenIdConnectConstants.Metadata.RequestParameterSupported] = false;
context.Metadata[OpenIdConnectConstants.Metadata.RequestUriParameterSupported] = false; context.Metadata[OpenIdConnectConstants.Metadata.RequestUriParameterSupported] = false;
context.Metadata[OpenIddictConstants.Metadata.ExternalProvidersSupported] = new JArray(
from provider in context.HttpContext.Authentication.GetAuthenticationSchemes()
where !string.IsNullOrEmpty(provider.DisplayName)
select provider.AuthenticationScheme);
return base.HandleConfigurationRequest(context); return base.HandleConfigurationRequest(context);
} }
} }

22
test/OpenIddict.Server.Tests/Internal/OpenIddictServerProviderTests.Discovery.cs

@ -7,11 +7,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using AspNet.Security.OpenIdConnect.Client; using AspNet.Security.OpenIdConnect.Client;
using AspNet.Security.OpenIdConnect.Primitives; using AspNet.Security.OpenIdConnect.Primitives;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.Facebook;
using Microsoft.AspNetCore.Authentication.Google;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using OpenIddict.Abstractions;
using Xunit; using Xunit;
namespace OpenIddict.Server.Tests namespace OpenIddict.Server.Tests
@ -236,23 +232,5 @@ namespace OpenIddict.Server.Tests
Assert.False((bool) response[OpenIdConnectConstants.Metadata.RequestParameterSupported]); Assert.False((bool) response[OpenIdConnectConstants.Metadata.RequestParameterSupported]);
Assert.False((bool) response[OpenIdConnectConstants.Metadata.RequestUriParameterSupported]); Assert.False((bool) response[OpenIdConnectConstants.Metadata.RequestUriParameterSupported]);
} }
[Fact]
public async Task HandleConfigurationRequest_ExternalProvidersAreCorrectlyReturned()
{
// Arrange
var server = CreateAuthorizationServer();
var client = new OpenIdConnectClient(server.CreateClient());
// Act
var response = await client.GetAsync(ConfigurationEndpoint);
var providers = ((JArray) response[OpenIddictConstants.Metadata.ExternalProvidersSupported]).Values<string>();
// Assert
Assert.DoesNotContain(CookieAuthenticationDefaults.AuthenticationScheme, providers);
Assert.Contains(FacebookDefaults.AuthenticationScheme, providers);
Assert.Contains(GoogleDefaults.AuthenticationScheme, providers);
}
} }
} }

19
test/OpenIddict.Server.Tests/Internal/OpenIddictServerProviderTests.cs

@ -15,7 +15,6 @@ using AspNet.Security.OpenIdConnect.Client;
using AspNet.Security.OpenIdConnect.Extensions; using AspNet.Security.OpenIdConnect.Extensions;
using AspNet.Security.OpenIdConnect.Primitives; using AspNet.Security.OpenIdConnect.Primitives;
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Diagnostics;
@ -1418,24 +1417,6 @@ namespace OpenIddict.Server.Tests
return next(context); return next(context);
}); });
app.UseCookieAuthentication();
// Note: the following client_id/client_secret are fake and are only
// used to test the metadata returned by the discovery endpoint.
app.UseFacebookAuthentication(new FacebookOptions
{
ClientId = "16018790-E88E-4553-8036-BB342579FF19",
ClientSecret = "3D6499AF-5607-489B-815A-F3ACF1617296",
SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme
});
app.UseGoogleAuthentication(new GoogleOptions
{
ClientId = "BAF437A5-87FA-4D06-8EFD-F9BA96CCEDC4",
ClientSecret = "27DF07D3-6B03-4EE0-95CD-3AC16782216B",
SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme
});
app.UseOpenIddictServer(); app.UseOpenIddictServer();
app.Run(context => app.Run(context =>

3
test/OpenIddict.Server.Tests/OpenIddict.Server.Tests.csproj

@ -17,9 +17,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="AspNet.Security.OpenIdConnect.Client" Version="$(AspNetContribOpenIdServerVersion)" /> <PackageReference Include="AspNet.Security.OpenIdConnect.Client" Version="$(AspNetContribOpenIdServerVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="$(AspNetCoreVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(AspNetCoreVersion)" /> <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="$(AspNetCoreVersion)" /> <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="$(AspNetCoreVersion)" />

Loading…
Cancel
Save