Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into VIH-10554-Demo-Change
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaed Parkar committed May 16, 2024
2 parents e32218e + 4b190d7 commit 3b8ef70
Show file tree
Hide file tree
Showing 253 changed files with 14,322 additions and 6,333 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,4 @@ TESTS.xml
Coverage/
**/SpecFlow/userid
.angular/
.nx/
7 changes: 7 additions & 0 deletions VideoWeb/VideoWeb.Common/Configuration/RedisConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VideoWeb.Common.Configuration;

public class RedisConfiguration
{
public string Endpoint { get; set; }
public string Password { get; set; }
}
44 changes: 44 additions & 0 deletions VideoWeb/VideoWeb.Common/FeatureToggles.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using LaunchDarkly.Logging;
using LaunchDarkly.Sdk;
using LaunchDarkly.Sdk.Server;
using LaunchDarkly.Sdk.Server.Interfaces;

namespace VideoWeb.Common;

public interface IFeatureToggles
{
public bool Vodafone();
}

public class FeatureToggles : IFeatureToggles
{
private readonly ILdClient _ldClient;
private readonly Context _context;
private const string LdUser = "vh-video-web";
private const string VodafoneToggleKey = "vodafone";

public FeatureToggles(string sdkKey, string environmentName)
{
var config = LaunchDarkly.Sdk.Server.Configuration.Builder(sdkKey)
.Logging(Components.Logging(Logs.ToWriter(Console.Out)).Level(LogLevel.Warn)).Build();
_context = Context.Builder(LdUser).Name(environmentName).Build();
_ldClient = new LdClient(config);
}

public bool Vodafone()
{
return GetBoolValueWithKey(VodafoneToggleKey);
}

private bool GetBoolValueWithKey(string key)
{
if (!_ldClient.Initialized)
{
throw new InvalidOperationException("LaunchDarkly client not initialized");
}

return _ldClient.BoolVariation(key, _context);
}
}

14 changes: 1 addition & 13 deletions VideoWeb/VideoWeb.Common/Security/HashGen/KinlyConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
namespace VideoWeb.Common.Security.HashGen
{
public class KinlyConfiguration
public class KinlyConfiguration : SupplierConfiguration
{
public string CallbackSecret { get; set; }
public string Audience { get; set; }
public string Issuer { get; set; }
public string ApiSecret { get; set; }
public string SelfTestApiSecret { get; set; }
public int ExpiresInMinutes { get; set; }
public int HashExpiresInMinutes { get; set; }
public string JoinByPhoneFromDate { get; set; }
public string TurnServer { get; set; }
public string TurnServerUser { get; set; }
public string TurnServerCredential { get; set; }
public string HeartbeatUrlBase { get; set; }
}
}
18 changes: 18 additions & 0 deletions VideoWeb/VideoWeb.Common/Security/HashGen/SupplierConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace VideoWeb.Common.Security.HashGen
{
public abstract class SupplierConfiguration
{
public string CallbackSecret { get; set; }
public string Audience { get; set; }
public string Issuer { get; set; }
public string ApiSecret { get; set; }
public string SelfTestApiSecret { get; set; }
public int ExpiresInMinutes { get; set; }
public int HashExpiresInMinutes { get; set; }
public string JoinByPhoneFromDate { get; set; }
public string TurnServer { get; set; }
public string TurnServerUser { get; set; }
public string TurnServerCredential { get; set; }
public string HeartbeatUrlBase { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace VideoWeb.Common.Security.HashGen;

public class VodafoneConfiguration : SupplierConfiguration
{
}
8 changes: 0 additions & 8 deletions VideoWeb/VideoWeb.Common/Security/IKinlyJwtTokenProvider.cs

This file was deleted.

47 changes: 0 additions & 47 deletions VideoWeb/VideoWeb.Common/Security/KinlyJwtTokenProvider.cs

This file was deleted.

42 changes: 42 additions & 0 deletions VideoWeb/VideoWeb.Common/Security/SupplierLocator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using VideoWeb.Common.Security.HashGen;
using VideoWeb.Common.Security.Tokens.Base;
using VideoWeb.Common.Security.Tokens.Kinly;
using VideoWeb.Common.Security.Tokens.Vodafone;

namespace VideoWeb.Common.Security;

public interface ISupplierLocator
{
IJwtTokenProvider GetTokenProvider();
IOptions<SupplierConfiguration> GetSupplierConfiguration();
}

public class SupplierLocator : ISupplierLocator
{
private readonly IServiceProvider _serviceProvider;
private readonly IOptions<KinlyConfiguration> _kinlyConfigOptions;
private readonly IOptions<VodafoneConfiguration> _vodafoneConfigOptions;
private readonly IFeatureToggles _featureToggles;

public SupplierLocator(IServiceProvider serviceProvider,
IFeatureToggles featureToggles,
IOptions<KinlyConfiguration> kinlyConfigOptions,
IOptions<VodafoneConfiguration> vodafoneConfigOptions)
{
_serviceProvider = serviceProvider;
_featureToggles = featureToggles;
_kinlyConfigOptions = kinlyConfigOptions;
_vodafoneConfigOptions = vodafoneConfigOptions;
}

public IJwtTokenProvider GetTokenProvider() => _featureToggles.Vodafone()
? _serviceProvider.GetService<IVodafoneJwtTokenProvider>()
: _serviceProvider.GetService<IKinlyJwtTokenProvider>();

public IOptions<SupplierConfiguration> GetSupplierConfiguration() =>
_featureToggles.Vodafone() ? _vodafoneConfigOptions : _kinlyConfigOptions;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.Extensions.Options;
using VideoWeb.Common.Configuration;

namespace VideoWeb.Common.Security
namespace VideoWeb.Common.Security.Tokens.Base
{
public abstract class BaseServiceTokenHandler : DelegatingHandler
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace VideoWeb.Common.Security.Tokens.Base;

public interface IJwtTokenProvider
{
string GenerateTokenForCallbackEndpoint(string claims, int expiresInMinutes);
string GenerateToken(string claims, int expiresInMinutes);
}
46 changes: 46 additions & 0 deletions VideoWeb/VideoWeb.Common/Security/Tokens/Base/JwtTokenProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using Microsoft.IdentityModel.Tokens;
using VideoWeb.Common.Security.HashGen;

namespace VideoWeb.Common.Security.Tokens.Base;

public abstract class JwtTokenProvider : IJwtTokenProvider
{
private readonly SupplierConfiguration _supplierConfiguration;

protected JwtTokenProvider(SupplierConfiguration supplierConfiguration)
{
_supplierConfiguration = supplierConfiguration;
}

public string GenerateTokenForCallbackEndpoint(string claims, int expiresInMinutes)
{
var key = Convert.FromBase64String(_supplierConfiguration.CallbackSecret);
return BuildToken(claims, expiresInMinutes, key);
}

public string GenerateToken(string claims, int expiresInMinutes)
{
var key = Convert.FromBase64String(_supplierConfiguration.ApiSecret);
return BuildToken(claims, expiresInMinutes, key);
}

private string BuildToken(string claims, int expiresInMinutes, byte[] key)
{
var securityKey = new SymmetricSecurityKey(key);
var descriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new[] {new Claim(ClaimTypes.Name, claims)}),
NotBefore = DateTime.UtcNow.AddMinutes(-1),
Issuer = _supplierConfiguration.Issuer,
Expires = DateTime.UtcNow.AddMinutes(expiresInMinutes + 1),
SigningCredentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha512)
};

var handler = new JwtSecurityTokenHandler();
var token = handler.CreateJwtSecurityToken(descriptor);
return handler.WriteToken(token);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
using VideoWeb.Common.Configuration;
using VideoWeb.Common.Security.Tokens.Base;

namespace VideoWeb.Common.Security
namespace VideoWeb.Common.Security.Tokens
{
public class BookingsApiTokenHandler : BaseServiceTokenHandler
{
Expand All @@ -16,4 +17,4 @@ public BookingsApiTokenHandler(IOptions<AzureAdConfiguration> azureAdConfigurati
protected override string TokenCacheKey => "BookingsApiServiceToken";
protected override string ClientResource => HearingServicesConfiguration.BookingsApiResourceId;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using VideoWeb.Common.Security.Tokens.Base;

namespace VideoWeb.Common.Security.Tokens.Kinly;

public interface IKinlyJwtTokenProvider : IJwtTokenProvider
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using VideoWeb.Common.Security.HashGen;
using VideoWeb.Common.Security.Tokens.Base;

namespace VideoWeb.Common.Security.Tokens.Kinly;

public class KinlyJwtTokenProvider : JwtTokenProvider, IKinlyJwtTokenProvider
{
public KinlyJwtTokenProvider(KinlyConfiguration supplierConfiguration) : base(supplierConfiguration)
{
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.Identity.Client;
using VideoWeb.Common.Configuration;

namespace VideoWeb.Common.Security
namespace VideoWeb.Common.Security.Tokens
{
public interface ITokenProvider
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
using VideoWeb.Common.Configuration;
using VideoWeb.Common.Security.Tokens.Base;

namespace VideoWeb.Common.Security
namespace VideoWeb.Common.Security.Tokens
{
public class UserApiTokenHandler : BaseServiceTokenHandler
{
Expand All @@ -16,4 +17,4 @@ public UserApiTokenHandler(IOptions<AzureAdConfiguration> azureAdConfiguration,
protected override string TokenCacheKey => "UserApiServiceToken";
protected override string ClientResource => HearingServicesConfiguration.UserApiResourceId;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
using VideoWeb.Common.Configuration;
using VideoWeb.Common.Security.Tokens.Base;

namespace VideoWeb.Common.Security
namespace VideoWeb.Common.Security.Tokens
{
public class VideoApiTokenHandler : BaseServiceTokenHandler
{
Expand All @@ -16,4 +17,4 @@ public VideoApiTokenHandler(IOptions<AzureAdConfiguration> azureAdConfiguration,
protected override string TokenCacheKey => "VideoApiServiceToken";
protected override string ClientResource => HearingServicesConfiguration.VideoApiResourceId;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using VideoWeb.Common.Security.Tokens.Base;

namespace VideoWeb.Common.Security.Tokens.Vodafone;

public interface IVodafoneJwtTokenProvider : IJwtTokenProvider
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using VideoWeb.Common.Security.HashGen;
using VideoWeb.Common.Security.Tokens.Base;

namespace VideoWeb.Common.Security.Tokens.Vodafone;

public class VodafoneJwtTokenProvider : JwtTokenProvider, IVodafoneJwtTokenProvider
{
public VodafoneJwtTokenProvider(VodafoneConfiguration vodafoneConfiguration) : base(vodafoneConfiguration)
{
}
}

3 changes: 2 additions & 1 deletion VideoWeb/VideoWeb.Common/VideoWeb.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BookingsApi.Client" Version="1.51.12" />
<PackageReference Include="BookingsApi.Client" Version="2.0.4" />
<PackageReference Include="LaunchDarkly.ServerSdk" Version="7.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.16.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.16.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
Expand Down
Loading

0 comments on commit 3b8ef70

Please sign in to comment.