-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #275 from ITfoxtec/1.1.x-net6
1.1.x net6
- Loading branch information
Showing
62 changed files
with
756 additions
and
643 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/FoxIDs.Control/Controllers/Helpers/TReadCertificateController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using AutoMapper; | ||
using FoxIDs.Infrastructure; | ||
using Api = FoxIDs.Models.Api; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Threading.Tasks; | ||
using ITfoxtec.Identity; | ||
using System.Security.Cryptography.X509Certificates; | ||
using Microsoft.AspNetCore.WebUtilities; | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace FoxIDs.Controllers | ||
{ | ||
public class TReadCertificateController : TenantApiController | ||
{ | ||
private readonly IMapper mapper; | ||
|
||
public TReadCertificateController(TelemetryScopedLogger logger, IMapper mapper) : base(logger) | ||
{ | ||
this.mapper = mapper; | ||
} | ||
|
||
/// <summary> | ||
/// Read JWT with certificate information. | ||
/// </summary> | ||
/// <param name="certificateAndPassword">Base64 url encode certificate and optionally password.</param> | ||
/// <returns>User.</returns> | ||
[ProducesResponseType(typeof(Api.JwtWithCertificateInfo), StatusCodes.Status200OK)] | ||
public async Task<ActionResult<Api.JwtWithCertificateInfo>> PostReadCertificate([FromBody] Api.CertificateAndPassword certificateAndPassword) | ||
{ | ||
if (!await ModelState.TryValidateObjectAsync(certificateAndPassword)) return BadRequest(ModelState); | ||
|
||
try | ||
{ | ||
var certificate = certificateAndPassword.Password.IsNullOrWhiteSpace() switch | ||
{ | ||
true => new X509Certificate2(WebEncoders.Base64UrlDecode(certificateAndPassword.EncodeCertificate), string.Empty, keyStorageFlags: X509KeyStorageFlags.Exportable), | ||
false => new X509Certificate2(WebEncoders.Base64UrlDecode(certificateAndPassword.EncodeCertificate), certificateAndPassword.Password, keyStorageFlags: X509KeyStorageFlags.Exportable), | ||
}; | ||
|
||
var jwt = await certificate.ToFTJsonWebKeyAsync(includePrivateKey: true); | ||
return Ok(mapper.Map<Api.JwtWithCertificateInfo>(jwt)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new ValidationException("Unable to read certificate.", ex); | ||
} | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/FoxIDs.Control/Controllers/Parties/TSamlUpPartyReadMetadataController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using AutoMapper; | ||
using FoxIDs.Infrastructure; | ||
using Api = FoxIDs.Models.Api; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Threading.Tasks; | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using FoxIDs.Logic; | ||
using FoxIDs.Models; | ||
|
||
namespace FoxIDs.Controllers | ||
{ | ||
public class TSamlUpPartyReadMetadataController : TenantApiController | ||
{ | ||
private readonly IMapper mapper; | ||
private readonly SamlMetadataReadLogic samlMetadataReadLogic; | ||
|
||
public TSamlUpPartyReadMetadataController(TelemetryScopedLogger logger, IMapper mapper, SamlMetadataReadLogic samlMetadataReadLogic) : base(logger) | ||
{ | ||
this.mapper = mapper; | ||
this.samlMetadataReadLogic = samlMetadataReadLogic; | ||
} | ||
|
||
/// <summary> | ||
/// Read saml 2.0 up-party metadata. | ||
/// </summary> | ||
/// <param name="samlReadMetadataRequest">SAML 2.0 metadata.</param> | ||
/// <returns>SAML 2.0 up-party.</returns> | ||
[ProducesResponseType(typeof(Api.SamlUpParty), StatusCodes.Status200OK)] | ||
public async Task<ActionResult<Api.SamlUpParty>> PostSamlUpPartyReadMetadata([FromBody] Api.SamlReadMetadataRequest samlReadMetadataRequest) | ||
{ | ||
if (!await ModelState.TryValidateObjectAsync(samlReadMetadataRequest)) return BadRequest(ModelState); | ||
|
||
try | ||
{ | ||
var samlUpParty = new SamlUpParty { AuthnBinding = new SamlBinding() }; | ||
switch (samlReadMetadataRequest.Type) | ||
{ | ||
case Api.SamlReadMetadataType.Url: | ||
samlUpParty.MetadataUrl = samlReadMetadataRequest.Metadata; | ||
await samlMetadataReadLogic.PopulateModelAsync(samlUpParty); | ||
break; | ||
case Api.SamlReadMetadataType.Xml: | ||
await samlMetadataReadLogic.PopulateModelAsync(samlUpParty, samlReadMetadataRequest.Metadata); | ||
break; | ||
default: | ||
throw new NotSupportedException(); | ||
} | ||
return Ok(mapper.Map<Api.SamlUpParty>(samlUpParty)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new ValidationException("Unable to read SAML 2.0 metadata.", ex); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.