Merge pull request #57 from ThreeMammals/develop

merge
This commit is contained in:
geffzhang 2019-03-12 08:47:06 +08:00 committed by GitHub
commit e2c170e2c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 12 deletions

View File

@ -138,8 +138,28 @@ Then map the authentication provider key to a ReRoute in your configuration e.g.
Okta
^^^^
Add nuget package : `"Okta.AspNetCore" https://www.nuget.org/packages/Okta.AspNetCore/`_
I have not had time to write this up but we have `Issue 446 <https://github.com/ThreeMammals/Ocelot/issues/446>`_ that contains some code and examples that might help with Okta integration.
In a StartUp.cs file add to a method Configure next lines:
app.UseAuthentication();
app.UseOcelot().Wait();
In a StartUp.cs file add to a method ConfigureServices lines:
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = OktaDefaults.ApiAuthenticationScheme;
options.DefaultChallengeScheme = OktaDefaults.ApiAuthenticationScheme;
options.DefaultSignInScheme = OktaDefaults.ApiAuthenticationScheme;
})
.AddOktaWebApi(new OktaWebApiOptions
{
OktaDomain = _cfg["Okta:OktaDomain"]
});
services.AddOcelot(_cfg);
`Issue 446 <https://github.com/ThreeMammals/Ocelot/issues/446>`_ that contains some code and examples that might help with Okta integration.
Allowed Scopes
^^^^^^^^^^^^^

View File

@ -2,6 +2,16 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0-dev</Version>
<Authors>geffzhang</Authors>
<Company />
<Product>Ocelot</Product>
<Description>Provides Ocelot extensions to use kubernetes</Description>
<PackageProjectUrl>https://github.com/ThreeMammals/Ocelot</PackageProjectUrl>
<PackageIconUrl>http://threemammals.com/images/ocelot_logo.png</PackageIconUrl>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageTags>API Gateway;.NET core</PackageTags>
</PropertyGroup>
<ItemGroup>

View File

@ -12,6 +12,8 @@ namespace Ocelot.DependencyInjection
IConfiguration Configuration { get; }
IMvcCoreBuilder MvcCoreBuilder { get; }
IOcelotBuilder AddDelegatingHandler<T>(bool global = false)
where T : DelegatingHandler;

View File

@ -42,6 +42,7 @@ namespace Ocelot.DependencyInjection
{
public IServiceCollection Services { get; }
public IConfiguration Configuration { get; }
public IMvcCoreBuilder MvcCoreBuilder { get; }
public OcelotBuilder(IServiceCollection services, IConfiguration configurationRoot)
{
@ -133,17 +134,18 @@ namespace Ocelot.DependencyInjection
//add asp.net services..
var assembly = typeof(FileConfigurationController).GetTypeInfo().Assembly;
Services.AddMvcCore()
.AddApplicationPart(assembly)
.AddControllersAsServices()
.AddAuthorization()
.AddJsonFormatters();
this.MvcCoreBuilder = Services.AddMvcCore()
.AddApplicationPart(assembly)
.AddControllersAsServices()
.AddAuthorization()
.AddJsonFormatters();
Services.AddLogging();
Services.AddMiddlewareAnalysis();
Services.AddWebEncoders();
}
public IOcelotBuilder AddSingletonDefinedAggregator<T>()
where T : class, IDefinedAggregator
{
@ -170,7 +172,7 @@ namespace Ocelot.DependencyInjection
if(global)
{
Services.AddTransient<THandler>();
Services.AddTransient<GlobalDelegatingHandler>(s => {
Services.AddTransient<GlobalDelegatingHandler>(s =>{
var service = s.GetService<THandler>();
return new GlobalDelegatingHandler(service);
});

View File

@ -1,6 +1,6 @@
namespace Ocelot.Infrastructure.Claims.Parser
{
using Errors;
using Microsoft.Extensions.Primitives;
using Responses;
using System.Collections.Generic;
using System.Linq;
@ -45,11 +45,11 @@
private Response<string> GetValue(IEnumerable<Claim> claims, string key)
{
var claim = claims.FirstOrDefault(c => c.Type == key);
var claimValues = claims.Where(c => c.Type == key).Select(c => c.Value).ToArray();
if (claim != null)
if (claimValues.Length > 0)
{
return new OkResponse<string>(claim.Value);
return new OkResponse<string>(new StringValues(claimValues).ToString());
}
return new ErrorResponse<string>(new CannotFindClaimError($"Cannot find claim for key: {key}"));