Skip to content

Commit

Permalink
Fix authentication (#611)
Browse files Browse the repository at this point in the history
* fix authentication

* bump version
  • Loading branch information
nataly87s committed Sep 13, 2017
1 parent dd0e504 commit 27b3b7c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "api-build",
"program": "${workspaceRoot}/services/api/Tweek.ApiService.NetCore/bin/Debug/netcoreapp1.1/Tweek.ApiService.NetCore.dll",
"program": "${workspaceRoot}/services/api/Tweek.ApiService.NetCore/bin/Debug/netcoreapp2.0/Tweek.ApiService.NetCore.dll",
"args": [],
"cwd": "${workspaceRoot}/services/api/Tweek.ApiService.NetCore",
"stopAtEntry": false,
Expand All @@ -25,6 +25,7 @@
}
},
"env": {
"PUBLIC_KEY_PATH": "../../git-service/ssh/tweekgit_public.pfx",
"Rules__Management__Url": "http://localhost:4002",
"ASPNETCORE_ENVIRONMENT": "Development",
"Addons__Redis__className": "Tweek.Drivers.Redis.RedisServiceAddon",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@

namespace Tweek.ApiService.NetCore.Security
{
public class JwtAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
public class JwtAuthenticationSchemeOptions : AuthenticationSchemeOptions {
public ImmutableHashSet<string> AuthProviders {get;set;}
}

public class JwtAuthenticationHandler : AuthenticationHandler<JwtAuthenticationSchemeOptions>
{
private readonly ImmutableHashSet<string> _authProviters;
public JwtAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, IConfiguration configuration, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock)
{
_authProviters = configuration.GetSection("Security:Providers")
.GetChildren()
.Select(x => x["Issuer"])
.Append("tweek")
.ToImmutableHashSet();
}
public JwtAuthenticationHandler(IOptionsMonitor<JwtAuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock)
: base(options, logger, encoder, clock)
{ }

protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
{
Expand All @@ -44,7 +42,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()

var issuer = jwtSecurityToken.Issuer;

if (_authProviters.Contains(issuer))
if (Options.AuthProviders.Contains(issuer))
{
return await Context.AuthenticateAsync($"JWT {issuer}");
}
Expand Down Expand Up @@ -82,7 +80,11 @@ public void Install(AuthenticationBuilder app, IConfiguration configuration, ILo
});
});

app.AddScheme<AuthenticationSchemeOptions, JwtAuthenticationHandler>(JwtBearerDefaults.AuthenticationScheme, _ => { });
var optionsAuthProvider = authProviders.Select(x => x["Issuer"])
.Append("tweek")
.ToImmutableHashSet();

app.AddScheme<JwtAuthenticationSchemeOptions, JwtAuthenticationHandler>(JwtBearerDefaults.AuthenticationScheme, options => options.AuthProviders = optionsAuthProvider);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<VersionPrefix>0.2.0</VersionPrefix>
<VersionPrefix>0.2.1</VersionPrefix>
<DockerComposeProjectPath>..\..\..\deployments\docker-compose.dcproj</DockerComposeProjectPath>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1591, 1701, 1702, 1998</NoWarn>
Expand Down
1 change: 1 addition & 0 deletions services/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-loader": "^7.1.2",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.6.0",
Expand Down
28 changes: 28 additions & 0 deletions services/editor/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,14 @@ babel-loader@7.0.0:
loader-utils "^1.0.2"
mkdirp "^0.5.1"

babel-loader@^7.1.2:
version "7.1.2"
resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-7.1.2.tgz#f6cbe122710f1aa2af4d881c6d5b54358ca24126"
dependencies:
find-cache-dir "^1.0.0"
loader-utils "^1.0.2"
mkdirp "^0.5.1"

babel-messages@^6.23.0:
version "6.23.0"
resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.23.0.tgz#f3cdf4703858035b2a2951c6ec5edf6c62f2630e"
Expand Down Expand Up @@ -3109,6 +3117,14 @@ find-cache-dir@^0.1.1:
mkdirp "^0.5.1"
pkg-dir "^1.0.0"

find-cache-dir@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-1.0.0.tgz#9288e3e9e3cc3748717d39eade17cf71fc30ee6f"
dependencies:
commondir "^1.0.1"
make-dir "^1.0.0"
pkg-dir "^2.0.0"

find-parent-dir@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/find-parent-dir/-/find-parent-dir-0.3.0.tgz#33c44b429ab2b2f0646299c5f9f718f376ff8d54"
Expand Down Expand Up @@ -4927,6 +4943,12 @@ macaddress@^0.2.8:
version "0.2.8"
resolved "https://registry.yarnpkg.com/macaddress/-/macaddress-0.2.8.tgz#5904dc537c39ec6dbefeae902327135fa8511f12"

make-dir@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.0.0.tgz#97a011751e91dd87cfadef58832ebb04936de978"
dependencies:
pify "^2.3.0"

make-plural@~3.0.6:
version "3.0.6"
resolved "https://registry.yarnpkg.com/make-plural/-/make-plural-3.0.6.tgz#2033a03bac290b8f3bb91258f65b9df7e8b01ca7"
Expand Down Expand Up @@ -5743,6 +5765,12 @@ pkg-dir@^1.0.0:
dependencies:
find-up "^1.0.0"

pkg-dir@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-2.0.0.tgz#f6d5d1109e19d63edf428e0bd57e12777615334b"
dependencies:
find-up "^2.1.0"

pkg-up@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/pkg-up/-/pkg-up-1.0.0.tgz#3e08fb461525c4421624a33b9f7e6d0af5b05a26"
Expand Down

0 comments on commit 27b3b7c

Please sign in to comment.