Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Controllers/Api/AlarmsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static async Task<bool> RenewAuthToken(PollingDataDTO pollingData, strin
{
using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
{
var terminalDO = await ObjectFactory.GetInstance<ITerminal>().GetByToken(terminalToken);
var terminalDO = await ObjectFactory.GetInstance<ITerminal>().GetByKey(terminalToken);
if (terminalDO == null)
{
throw new Exception("No terminal was found with token: "+terminalToken);
Expand Down
1 change: 0 additions & 1 deletion Controllers/Api/PlansController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ public async Task<IHttpActionResult> Unpublish(Guid planId)
/// <response code="403">Unauthorized request</response>
[Fr8ApiAuthorize("Admin", "StandardUser", "Terminal")]
[Fr8TerminalAuthentication]
[Fr8PlanDirectoryAuthentication]
[HttpPost]
[ResponseType(typeof(PlanNoChildrenDTO))]
public async Task<IHttpActionResult> Load(PlanDTO plan)
Expand Down
6 changes: 3 additions & 3 deletions Controllers/Api/WarehousesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class WarehousesController : ApiController
/// <param name="query">Query filter</param>
/// <response code="200">Collection of queried objects</response>
/// <response code="403">Unauthorized request</response>
[Fr8TerminalAuthentication(true)]
[Fr8TerminalAuthentication]
[HttpPost]
[ResponseType(typeof(object[]))]
public IHttpActionResult Query(QueryDTO query)
Expand All @@ -48,7 +48,7 @@ public IHttpActionResult Query(QueryDTO query)
/// </summary>
/// <remarks>Fr8 authentication headers must be provided</remarks>
/// <param name="query">Query filter</param>
[Fr8TerminalAuthentication(true)]
[Fr8TerminalAuthentication]
[HttpPost]
[SwaggerResponse(HttpStatusCode.OK, "Objects were succesfully deleted")]
[SwaggerResponse(HttpStatusCode.Unauthorized, "Unauthorized request", typeof(ErrorDTO))]
Expand All @@ -73,7 +73,7 @@ public IHttpActionResult Delete(QueryDTO query)
/// </summary>
/// <remarks>Fr8 authentication headers must be provided</remarks>
/// <param name="crateStorageDto">Crates to store in Fr8 warehouse</param>
[Fr8TerminalAuthentication(true)]
[Fr8TerminalAuthentication]
[HttpPost]
[SwaggerResponse(HttpStatusCode.OK, "Objects were succesfully saved")]
[SwaggerResponse(HttpStatusCode.Unauthorized, "Unauthorized request", typeof(ErrorDTO))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,30 @@ Terminals often needs to communicate with the Hub. Some examples include getting

## Authentication your Terminal

Each request from the Hub to your Terminal includes these 2 properties:
Each request from the Hub to your Terminal includes these 2 headers:

* **TerminalKey**: 4b54d12f7f834648be28aa247f523e21
* **CurrentHubUrl**: http://dev.fr8.co/

### Terminal Key

The Hub generates this when it learns about a new Terminal. It functions in most respects as your Terminal's ID value but can be changed if it has been compromised. All of your Http requests need to include it in the header:

Authorization: FR8 terminal_key=2db48191-cda3-4922-9cc2-a636e828063f
The Hub generates this when it learns about a new Terminal. It functions in most respects as your Terminal's ID value but can be changed if it has been compromised. All of your Http requests need to include it in the header:

### HubUrl

This is the endpoint of the Hub that is making the request.

This is the endpoint of the Hub that is making the request.
Fr8 is a distributed environment. Your terminal might be in use by many Hubs. This property lets you know which Hub to respond to.



### Generating your Authentication Header

When your terminal needs to make a request to the Hub, it needs to provide an authorization header with the terminal key

Example:

Authorization: FR8-TOKEN key=2db48191-cda3-4922-9cc2-a636e828063f
Authorization: FR8 terminal_key=2db48191-cda3-4922-9cc2-a636e828063f


###Note. It was previously also necessary to put the ID of the current user session into the authorization header, but that has been removed.
###Note. It was previously also necessary to put the ID of the current user session into the authorization header, but that has been removed.

[Go to Contents](/Docs/Home.md)
12 changes: 4 additions & 8 deletions Fr8TerminalBase.NET/BaseClasses/BaseConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,17 @@ public IHttpController Create(HttpRequestMessage request, HttpControllerDescript
//it can only communicate with master hub for general purpose queries
//or it can get a list of all hubs from discovery service

if (request.Headers.Contains("Fr8HubCallBackUrl") && request.Headers.Contains("Fr8HubCallbackSecret"))
if (request.Headers.Contains("CurrentHubUrl") && request.Headers.Contains("TerminalKey"))
{
var apiUrl = request.Headers.GetValues("Fr8HubCallBackUrl").First().TrimEnd('\\', '/') +
var apiUrl = request.Headers.GetValues("CurrentHubUrl").First().TrimEnd('\\', '/') +
$"/api/{CloudConfigurationManager.GetSetting("HubApiVersion")}";
var secret = request.Headers.GetValues("Fr8HubCallbackSecret").First();
var fr8UserId = request.Headers.Contains("Fr8UserId")
? request.Headers.GetValues("Fr8UserId").First()
: null;
var secret = request.Headers.GetValues("TerminalKey").First();
_hubDiscovery.SetHubSecret(apiUrl, secret);
hubCommunicatorFactoryExpression =
c =>
new DefaultHubCommunicator(
c.GetInstance<IRestfulServiceClientFactory>()
.Create(new HubAuthenticationHeaderSignature(secret, fr8UserId)), apiUrl, secret,
fr8UserId);
.Create(new HubAuthenticationHeaderSignature(secret)), apiUrl, secret);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace Fr8.TerminalBase.Infrastructure
public class HubAuthenticationHeaderSignature : IRequestSignature
{
private readonly string _fr8Token;
public HubAuthenticationHeaderSignature(string token, string userId)
public HubAuthenticationHeaderSignature(string token)
{
_fr8Token = $"key={token}" + (string.IsNullOrEmpty(userId) ? "" : $", user={userId}");
_fr8Token = $"FR8 terminal_key={token}";
}

public void SignRequest(HttpRequestMessage request)
{
request.Headers.Add(System.Net.HttpRequestHeader.Authorization.ToString(), $"FR8-TOKEN {_fr8Token}");
request.Headers.Add(System.Net.HttpRequestHeader.Authorization.ToString(), _fr8Token);
}
}
}
4 changes: 1 addition & 3 deletions Fr8TerminalBase.NET/Services/DefaultHubCommunicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ public class DefaultHubCommunicator : IHubCommunicator
private readonly string _apiUrl;
private string _userId;
protected string TerminalToken { get; set; }
public string UserId => _userId;

public DefaultHubCommunicator(IRestfulServiceClient restfulServiceClient, string apiUrl, string token, string userId)
public DefaultHubCommunicator(IRestfulServiceClient restfulServiceClient, string apiUrl, string token)
{
TerminalToken = token;
_restfulServiceClient = restfulServiceClient;
_apiUrl = apiUrl?.TrimEnd('/', '\\');
_userId = userId;
}

public async Task<PlanNoChildrenDTO> LoadPlan(PlanDTO planContents)
Expand Down
4 changes: 2 additions & 2 deletions Fr8TerminalBase.NET/Services/HubDiscoveryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public async Task<IHubCommunicator> GetHubCommunicator(string hubUrl)
}

var secret = await setSecretTask.Task;
var restfulServiceClient = _restfulServiceClientFactory.Create(new HubAuthenticationHeaderSignature(secret, null));
return new DefaultHubCommunicator(restfulServiceClient, string.Concat(hubUrl, _apiSuffix), secret, null);
var restfulServiceClient = _restfulServiceClientFactory.Create(new HubAuthenticationHeaderSignature(secret));
return new DefaultHubCommunicator(restfulServiceClient, string.Concat(hubUrl, _apiSuffix), secret);
}

/**********************************************************************************/
Expand Down
5 changes: 2 additions & 3 deletions Hub/Infrastructure/Fr8Identity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ namespace Hub.Infrastructure
{
public sealed class Fr8Identity : ClaimsIdentity
{
public Fr8Identity(string name, string userId) : base("hmac")
public Fr8Identity(string terminalKey) : base("FR8")
{
AddClaim(new Claim(ClaimTypes.Name, name));
AddClaim(new Claim(ClaimTypes.NameIdentifier, userId));
AddClaim(new Claim("TerminalKey", terminalKey));
}
}
}
6 changes: 3 additions & 3 deletions Hub/Infrastructure/Fr8Principal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ namespace Hub.Infrastructure
{
public class Fr8Principal : GenericPrincipal
{
private string TerminalId { get; set; }
private string TerminalKey { get; set; }

public Fr8Principal(string terminalId, IIdentity identity, string[] roles = null) : base(identity, roles)
public Fr8Principal(string terminalKey, IIdentity identity, string[] roles = null) : base(identity, roles)
{
TerminalId = terminalId;
TerminalKey = terminalKey;
}
}
}
4 changes: 2 additions & 2 deletions Hub/Interfaces/ITerminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public interface ITerminal
TerminalDO GetByKey(Guid terminalId);
TerminalDO GetByNameAndVersion(string name, string version);
TerminalDO RegisterOrUpdate(TerminalDO terminalDo, bool isDiscovery);
Dictionary<string, string> GetRequestHeaders(TerminalDO terminal, string userId);
Task<TerminalDO> GetByToken(string token);
Dictionary<string, string> GetRequestHeaders(TerminalDO terminal);
Task<TerminalDO> GetByKey(string key);
Task<List<DocumentationResponseDTO>> GetSolutionDocumentations(string terminalName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public async Task<TResponse> CallActivityAsync<TResponse>(
}

requestUri = new Uri(new Uri(terminal.Endpoint), requestUri);
return await PostAsync<Fr8DataDTO, TResponse>(requestUri, dataDTO, correlationId, _terminalService.GetRequestHeaders(terminal, dataDTO.ActivityDTO.AuthToken.UserId));
return await PostAsync<Fr8DataDTO, TResponse>(requestUri, dataDTO, correlationId, _terminalService.GetRequestHeaders(terminal));
}
}
}
11 changes: 5 additions & 6 deletions Hub/Services/Terminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public TerminalDO RegisterOrUpdate(TerminalDO terminalDo, bool isUserInitiated)
}
}

public Dictionary<string, string> GetRequestHeaders(TerminalDO terminal, string userId)
public Dictionary<string, string> GetRequestHeaders(TerminalDO terminal)
{
Initialize();

Expand All @@ -192,9 +192,8 @@ public Dictionary<string, string> GetRequestHeaders(TerminalDO terminal, string

return new Dictionary<string, string>
{
{"Fr8HubCallbackSecret", terminal.Secret},
{"Fr8HubCallBackUrl", _serverUrl},
{"Fr8UserId", userId }
{"TerminalKey", terminal.Secret},
{"CurrentHubUrl", _serverUrl}
};
}

Expand Down Expand Up @@ -259,13 +258,13 @@ public async Task<List<DocumentationResponseDTO>> GetSolutionDocumentations(stri
return solutionPages;
}

public async Task<TerminalDO> GetByToken(string token)
public async Task<TerminalDO> GetByKey(string key)
{
Initialize();

lock (_terminals)
{
return _terminals.Values.FirstOrDefault(t => t.Secret == token);
return _terminals.Values.FirstOrDefault(t => t.Secret == key);
}
}

Expand Down
6 changes: 3 additions & 3 deletions Hub/StructureMap/StructureMapBootStrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ public TerminalServiceForTests(IConfigRepository configRepository, ISecurityServ
_terminal = new Terminal(configRepository, securityServices);
}

public Dictionary<string, string> GetRequestHeaders(TerminalDO terminal, string userId)
public Dictionary<string, string> GetRequestHeaders(TerminalDO terminal)
{
return new Dictionary<string, string>();
}

public Task<TerminalDO> GetByToken(string token)
public Task<TerminalDO> GetByKey(string key)
{
return _terminal.GetByToken(token);
return _terminal.GetByKey(key);
}

public IEnumerable<TerminalDO> GetAll()
Expand Down
1 change: 0 additions & 1 deletion HubWeb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@
<Compile Include="Filters\RedirecLogedUserAttribute.cs" />
<Compile Include="Infrastructure_HubWeb\AngularTemplateCacheAttribute.cs" />
<Compile Include="Infrastructure_HubWeb\FileActionResult.cs" />
<Compile Include="Infrastructure_HubWeb\Fr8PlanDirectoryAuthenticationAttribute.cs" />
<Compile Include="Infrastructure_HubWeb\Fr8TerminalAuthenticationAttribute.cs" />
<Compile Include="Infrastructure_HubWeb\Fr8Identity.cs" />
<Compile Include="Infrastructure_HubWeb\HtmlHelpers.cs" />
Expand Down
128 changes: 0 additions & 128 deletions Infrastructure_HubWeb/Fr8PlanDirectoryAuthenticationAttribute.cs

This file was deleted.

Loading