mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 12:59:39 -07:00
stuff around tokens and also builds
This commit is contained in:
parent
366b0d575a
commit
66cc7f6f1a
13 changed files with 59 additions and 22 deletions
20
BuildTask.ps1
Normal file
20
BuildTask.ps1
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
param([String]$env='local',
|
||||||
|
[String]$ver='3.0.0',
|
||||||
|
[String]$basePath='')
|
||||||
|
|
||||||
|
"Environment: " + $env | Write-Output;
|
||||||
|
"Build Version: " + $ver | Write-Output;
|
||||||
|
"Base Path: " + $basePath | Write-Output;
|
||||||
|
|
||||||
|
$appSettingsPath = $basePath + '\src\Ombi\appsettings.json'
|
||||||
|
$appSettings = Get-Content $appSettingsPath -raw
|
||||||
|
$appSettings = $appSettings.Replace("{{VERSIONNUMBER}}",$ver);
|
||||||
|
Set-Content -Path $appSettingsPath -Value $appSettings
|
||||||
|
|
||||||
|
$configPath = $basePath + '\src\Ombi\wwwroot\app\config.ts';
|
||||||
|
$config = Get-Content $configPath -raw
|
||||||
|
|
||||||
|
$config = $config.Replace("{{ENVIRONMENT}}",$env);
|
||||||
|
$config | Write-Output
|
||||||
|
#Set-Content -Path $configPath -Value $config
|
|
@ -10,6 +10,7 @@ before_build:
|
||||||
- appveyor-retry npm install -g gulp
|
- appveyor-retry npm install -g gulp
|
||||||
- appveyor-retry npm install
|
- appveyor-retry npm install
|
||||||
- appveyor-retry bower install
|
- appveyor-retry bower install
|
||||||
|
- ps: %APPVEYOR_BUILD_FOLDER%\BuildTask.ps1 -env "live" -ver "%APPVEYOR_BUILD_VERSION%" -basePath "%APPVEYOR_BUILD_FOLDER%"
|
||||||
- gulp publish
|
- gulp publish
|
||||||
build_script:
|
build_script:
|
||||||
- dotnet build
|
- dotnet build
|
||||||
|
|
|
@ -57,7 +57,7 @@ namespace Ombi.DependencyInjection
|
||||||
{
|
{
|
||||||
services.AddEntityFrameworkSqlite().AddDbContext<OmbiContext>();
|
services.AddEntityFrameworkSqlite().AddDbContext<OmbiContext>();
|
||||||
|
|
||||||
services.AddTransient<IOmbiContext, OmbiContext>();
|
services.AddScoped<IOmbiContext, OmbiContext>();
|
||||||
services.AddTransient<IRequestRepository, RequestJsonRepository>();
|
services.AddTransient<IRequestRepository, RequestJsonRepository>();
|
||||||
services.AddTransient<ISettingsRepository, SettingsJsonRepository>();
|
services.AddTransient<ISettingsRepository, SettingsJsonRepository>();
|
||||||
services.AddTransient<IUserRepository, UserRepository>();
|
services.AddTransient<IUserRepository, UserRepository>();
|
||||||
|
|
|
@ -17,5 +17,6 @@ namespace Ombi.Store.Context
|
||||||
DbSet<User> Users { get; set; }
|
DbSet<User> Users { get; set; }
|
||||||
EntityEntry<T> Entry<T>(T entry) where T : class;
|
EntityEntry<T> Entry<T>(T entry) where T : class;
|
||||||
EntityEntry<TEntity> Attach<TEntity>(TEntity entity) where TEntity : class;
|
EntityEntry<TEntity> Attach<TEntity>(TEntity entity) where TEntity : class;
|
||||||
|
DbSet<TEntity> Set<TEntity>() where TEntity : class;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -41,11 +41,13 @@ namespace Ombi.Store.Repository
|
||||||
Db = ctx;
|
Db = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IOmbiContext Db { get; }
|
private IOmbiContext Db { get; }
|
||||||
|
|
||||||
public async Task<User> GetUser(string username)
|
public async Task<User> GetUser(string username)
|
||||||
{
|
{
|
||||||
return await Db.Users.FirstOrDefaultAsync(x => x.Username.ToLower() == username.ToLower());
|
var user = await Db.Users.FirstOrDefaultAsync(x => x.Username.ToLower() == username.ToLower());
|
||||||
|
Db.Entry(user).Reload();
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CreateUser(User user)
|
public async Task CreateUser(User user)
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 15.0.26403.7
|
VisualStudioVersion = 15.0.26430.6
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi", "Ombi\Ombi.csproj", "{C987AA67-AFE1-468F-ACD3-EAD5A48E1F6A}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi", "Ombi\Ombi.csproj", "{C987AA67-AFE1-468F-ACD3-EAD5A48E1F6A}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9D30CCF8-A115-4EB7-A34D-07780D752789}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9D30CCF8-A115-4EB7-A34D-07780D752789}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
..\appveyor.yml = ..\appveyor.yml
|
..\appveyor.yml = ..\appveyor.yml
|
||||||
|
..\BuildTask.ps1 = ..\BuildTask.ps1
|
||||||
Build\publish windows.bat = Build\publish windows.bat
|
Build\publish windows.bat = Build\publish windows.bat
|
||||||
Build\publish.bat = Build\publish.bat
|
Build\publish.bat = Build\publish.bat
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
|
|
11
src/Ombi/Auth/TokenAuthenticationOptions.cs
Normal file
11
src/Ombi/Auth/TokenAuthenticationOptions.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
namespace Ombi.Auth
|
||||||
|
{
|
||||||
|
public class TokenAuthenticationOptions
|
||||||
|
{
|
||||||
|
public string SecretKey { get; set; }
|
||||||
|
public string Issuer { get; set; }
|
||||||
|
public string Audience { get; set; }
|
||||||
|
public string TokenPath { get; set; }
|
||||||
|
public string CookieName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,7 +30,7 @@ namespace Ombi.Auth
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The expiration time for the generated tokens.
|
/// The expiration time for the generated tokens.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>The default is 7 Days.</remarks>
|
/// <remarks>The default is 1 Days.</remarks>
|
||||||
public TimeSpan Expiration { get; set; } = TimeSpan.FromDays(1);
|
public TimeSpan Expiration { get; set; } = TimeSpan.FromDays(1);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -9,24 +8,23 @@ using Microsoft.Extensions.Options;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Ombi.Auth;
|
using Ombi.Auth;
|
||||||
using Ombi.Core.IdentityResolver;
|
using Ombi.Core.IdentityResolver;
|
||||||
using Ombi.Core.Models;
|
|
||||||
|
|
||||||
namespace Ombi
|
namespace Ombi
|
||||||
{
|
{
|
||||||
public partial class Startup
|
public partial class Startup
|
||||||
{
|
{
|
||||||
|
|
||||||
public SymmetricSecurityKey signingKey;
|
public SymmetricSecurityKey SigningKey;
|
||||||
private void ConfigureAuth(IApplicationBuilder app)
|
private void ConfigureAuth(IApplicationBuilder app, IOptions<TokenAuthenticationOptions> options)
|
||||||
{
|
{
|
||||||
|
|
||||||
var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("secretkey_secretkey123!"));
|
var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(options.Value.SecretKey));
|
||||||
|
|
||||||
var tokenProviderOptions = new TokenProviderOptions
|
var tokenProviderOptions = new TokenProviderOptions
|
||||||
{
|
{
|
||||||
Path = "/api/v1/token/",
|
Path = options.Value.TokenPath,
|
||||||
Audience = "DemoAudience",
|
Audience = options.Value.Audience,
|
||||||
Issuer = "DemoIssuer",
|
Issuer = options.Value.Issuer,
|
||||||
SigningCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256),
|
SigningCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256),
|
||||||
IdentityResolver = GetIdentity
|
IdentityResolver = GetIdentity
|
||||||
};
|
};
|
||||||
|
@ -38,10 +36,10 @@ namespace Ombi
|
||||||
IssuerSigningKey = signingKey,
|
IssuerSigningKey = signingKey,
|
||||||
// Validate the JWT Issuer (iss) claim
|
// Validate the JWT Issuer (iss) claim
|
||||||
ValidateIssuer = true,
|
ValidateIssuer = true,
|
||||||
ValidIssuer = "DemoIssuer",
|
ValidIssuer = options.Value.Issuer,
|
||||||
// Validate the JWT Audience (aud) claim
|
// Validate the JWT Audience (aud) claim
|
||||||
ValidateAudience = true,
|
ValidateAudience = true,
|
||||||
ValidAudience = "DemoAudience",
|
ValidAudience = options.Value.Audience,
|
||||||
// Validate the token expiry
|
// Validate the token expiry
|
||||||
ValidateLifetime = true,
|
ValidateLifetime = true,
|
||||||
// If you want to allow a certain amount of clock drift, set that here:
|
// If you want to allow a certain amount of clock drift, set that here:
|
||||||
|
|
|
@ -13,6 +13,8 @@ using Microsoft.AspNetCore.StaticFiles;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Ombi.Auth;
|
||||||
using Ombi.DependencyInjection;
|
using Ombi.DependencyInjection;
|
||||||
using Ombi.Mapping;
|
using Ombi.Mapping;
|
||||||
using Ombi.Schedule;
|
using Ombi.Schedule;
|
||||||
|
@ -69,6 +71,7 @@ namespace Ombi
|
||||||
services.AddScoped<IPrincipal>(sp => sp.GetService<IHttpContextAccessor>().HttpContext.User);
|
services.AddScoped<IPrincipal>(sp => sp.GetService<IHttpContextAccessor>().HttpContext.User);
|
||||||
|
|
||||||
|
|
||||||
|
services.Configure<TokenAuthenticationOptions>(Configuration.GetSection("TokenAuthentication"));
|
||||||
|
|
||||||
services.AddHangfire(x =>
|
services.AddHangfire(x =>
|
||||||
{
|
{
|
||||||
|
@ -99,7 +102,7 @@ namespace Ombi
|
||||||
var jobSetup = (IJobSetup)app.ApplicationServices.GetService(typeof(IJobSetup));
|
var jobSetup = (IJobSetup)app.ApplicationServices.GetService(typeof(IJobSetup));
|
||||||
jobSetup.Setup();
|
jobSetup.Setup();
|
||||||
|
|
||||||
ConfigureAuth(app);
|
ConfigureAuth(app, (IOptions<TokenAuthenticationOptions>)app.ApplicationServices.GetService(typeof(IOptions<TokenAuthenticationOptions>)));
|
||||||
|
|
||||||
var provider = new FileExtensionContentTypeProvider();
|
var provider = new FileExtensionContentTypeProvider();
|
||||||
provider.Mappings[".map"] = "application/octet-stream";
|
provider.Mappings[".map"] = "application/octet-stream";
|
||||||
|
|
|
@ -5,10 +5,11 @@
|
||||||
"Default": "Warning"
|
"Default": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"Version": "{{VERSIONNUMBER}}",
|
||||||
"TokenAuthentication": {
|
"TokenAuthentication": {
|
||||||
"SecretKey": "secretkey_secretkey123!",
|
"SecretKey": "OmbiKey",
|
||||||
"Issuer": "DemoIssuer",
|
"Issuer": "OmbiIssuer",
|
||||||
"Audience": "DemoAudience",
|
"Audience": "OmbiAudience",
|
||||||
"TokenPath": "/api/v1/token/",
|
"TokenPath": "/api/v1/token/",
|
||||||
"CookieName": "access_token"
|
"CookieName": "access_token"
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ enum envs {
|
||||||
live = 2
|
live = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
var envVar = '{something}';
|
var envVar = '{{ENVIRONMENT}}';
|
||||||
var env = envs.local;
|
var env = envs.local;
|
||||||
if (envs[envVar]) {
|
if (envs[envVar]) {
|
||||||
env = envs[envVar];
|
env = envs[envVar];
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { Router } from '@angular/router';
|
||||||
|
|
||||||
import { AuthService } from '../auth/auth.service';
|
import { AuthService } from '../auth/auth.service';
|
||||||
import { StatusService } from '../services/status.service';
|
import { StatusService } from '../services/status.service';
|
||||||
import { IdentityService } from '../services/identity.service';
|
|
||||||
import { NotificationService } from '../services/notification.service';
|
import { NotificationService } from '../services/notification.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -12,7 +11,7 @@ import { NotificationService } from '../services/notification.service';
|
||||||
templateUrl: './login.component.html',
|
templateUrl: './login.component.html',
|
||||||
})
|
})
|
||||||
export class LoginComponent {
|
export class LoginComponent {
|
||||||
constructor(private authService: AuthService, private router: Router, private notify: NotificationService, private status: StatusService, private identityService: IdentityService) {
|
constructor(private authService: AuthService, private router: Router, private notify: NotificationService, private status: StatusService) {
|
||||||
this.status.getWizardStatus().subscribe(x => {
|
this.status.getWizardStatus().subscribe(x => {
|
||||||
if (!x.result) {
|
if (!x.result) {
|
||||||
this.router.navigate(['Wizard']);
|
this.router.navigate(['Wizard']);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue