Compare commits
2
Commits
788283f3a8
...
69f238f5b1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69f238f5b1 | ||
|
|
b1d7e20bef |
@@ -1,13 +1,14 @@
|
|||||||
namespace xCommons.Constants {
|
namespace xCommons.Constants {
|
||||||
public partial struct XAuthorization {
|
public partial struct XAuthorization {
|
||||||
public const string TokenIdentifier = "Bearer ";
|
public const string XApiKey = "X-Api-Key";
|
||||||
public const string Header = "Authorization";
|
public const string Header = "Authorization";
|
||||||
|
public const string ExpiresAt = "expires_at";
|
||||||
|
public const string XPoweredBy = "X-PoweredBy";
|
||||||
|
public const string TokenIdentifier = "Bearer ";
|
||||||
public const string AccessToken = "access_token";
|
public const string AccessToken = "access_token";
|
||||||
public const string RefreshToken = "refresh_token";
|
public const string RefreshToken = "refresh_token";
|
||||||
public const string ExpiresAt = "expires_at";
|
|
||||||
public const string AccessTokenExpired = "AccessToken-Expired";
|
|
||||||
public const string RevisionChecksum = "revision_checksum";
|
|
||||||
public const string XPoweredBy = "X-PoweredBy";
|
|
||||||
public const int ThresholdBeforeTokenExpiration = 600;
|
public const int ThresholdBeforeTokenExpiration = 600;
|
||||||
|
public const string RevisionChecksum = "revision_checksum";
|
||||||
|
public const string AccessTokenExpired = "AccessToken-Expired";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -304,10 +304,14 @@ namespace xCommons.Extensions
|
|||||||
/// Convert Using Auto Mapper ...
|
/// Convert Using Auto Mapper ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cfgAction"></param>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <typeparam name="E"></typeparam>
|
/// <typeparam name="E"></typeparam>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static T MapConvert<T, E>(this E source)
|
public static T MapConvert<T, E>(
|
||||||
|
this E source,
|
||||||
|
Action<IMapperConfigurationExpression> cfgAction = null
|
||||||
|
)
|
||||||
where T : class
|
where T : class
|
||||||
where E : class
|
where E : class
|
||||||
{
|
{
|
||||||
@@ -320,8 +324,16 @@ namespace xCommons.Extensions
|
|||||||
//
|
//
|
||||||
var dMapConfig = new MapperConfiguration(b =>
|
var dMapConfig = new MapperConfiguration(b =>
|
||||||
{
|
{
|
||||||
|
//
|
||||||
b.CreateMap<T, E>()
|
b.CreateMap<T, E>()
|
||||||
.ReverseMap();
|
.ReverseMap();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Use Specified Provided Actions if Exists ...
|
||||||
|
if (!cfgAction.IsNull())
|
||||||
|
{
|
||||||
|
cfgAction.Invoke(b);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
var dMapper = dMapConfig.CreateMapper();
|
var dMapper = dMapConfig.CreateMapper();
|
||||||
|
|
||||||
@@ -337,10 +349,14 @@ namespace xCommons.Extensions
|
|||||||
/// Convert Using Auto Mapper ...
|
/// Convert Using Auto Mapper ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cfgAction"></param>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <typeparam name="E"></typeparam>
|
/// <typeparam name="E"></typeparam>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IEnumerable<T> MapConvert<T, E>(this IEnumerable<E> source)
|
public static IEnumerable<T> MapConvert<T, E>(
|
||||||
|
this IEnumerable<E> source,
|
||||||
|
Action<IMapperConfigurationExpression> cfgAction = null
|
||||||
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
if (source.IsNull())
|
if (source.IsNull())
|
||||||
@@ -351,8 +367,16 @@ namespace xCommons.Extensions
|
|||||||
//
|
//
|
||||||
var dMapConfig = new MapperConfiguration(b =>
|
var dMapConfig = new MapperConfiguration(b =>
|
||||||
{
|
{
|
||||||
|
//
|
||||||
b.CreateMap<T, E>()
|
b.CreateMap<T, E>()
|
||||||
.ReverseMap();
|
.ReverseMap();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Use Specified Provided Actions if Exists ...
|
||||||
|
if (!cfgAction.IsNull())
|
||||||
|
{
|
||||||
|
cfgAction.Invoke(b);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
var dMapper = dMapConfig.CreateMapper();
|
var dMapper = dMapConfig.CreateMapper();
|
||||||
|
|
||||||
@@ -368,10 +392,14 @@ namespace xCommons.Extensions
|
|||||||
/// Convert Using Auto Mapper ...
|
/// Convert Using Auto Mapper ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cfgAction"></param>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <typeparam name="E"></typeparam>
|
/// <typeparam name="E"></typeparam>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static ICollection<T> MapConvert<T, E>(this ICollection<E> source)
|
public static ICollection<T> MapConvert<T, E>(
|
||||||
|
this ICollection<E> source,
|
||||||
|
Action<IMapperConfigurationExpression> cfgAction = null
|
||||||
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
if (source.IsNull())
|
if (source.IsNull())
|
||||||
@@ -382,8 +410,16 @@ namespace xCommons.Extensions
|
|||||||
//
|
//
|
||||||
var dMapConfig = new MapperConfiguration(b =>
|
var dMapConfig = new MapperConfiguration(b =>
|
||||||
{
|
{
|
||||||
|
//
|
||||||
b.CreateMap<T, E>()
|
b.CreateMap<T, E>()
|
||||||
.ReverseMap();
|
.ReverseMap();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Use Specified Provided Actions if Exists ...
|
||||||
|
if (!cfgAction.IsNull())
|
||||||
|
{
|
||||||
|
cfgAction.Invoke(b);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
var dMapper = dMapConfig.CreateMapper();
|
var dMapper = dMapConfig.CreateMapper();
|
||||||
|
|
||||||
@@ -399,10 +435,14 @@ namespace xCommons.Extensions
|
|||||||
/// Convert Using Auto Mapper ...
|
/// Convert Using Auto Mapper ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cfgAction"></param>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <typeparam name="E"></typeparam>
|
/// <typeparam name="E"></typeparam>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IList<T> MapConvert<T, E>(this IList<E> source)
|
public static IList<T> MapConvert<T, E>(
|
||||||
|
this IList<E> source,
|
||||||
|
Action<IMapperConfigurationExpression> cfgAction = null
|
||||||
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
if (source.IsNull())
|
if (source.IsNull())
|
||||||
@@ -413,8 +453,16 @@ namespace xCommons.Extensions
|
|||||||
//
|
//
|
||||||
var dMapConfig = new MapperConfiguration(b =>
|
var dMapConfig = new MapperConfiguration(b =>
|
||||||
{
|
{
|
||||||
|
//
|
||||||
b.CreateMap<T, E>()
|
b.CreateMap<T, E>()
|
||||||
.ReverseMap();
|
.ReverseMap();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Use Specified Provided Actions if Exists ...
|
||||||
|
if (!cfgAction.IsNull())
|
||||||
|
{
|
||||||
|
cfgAction.Invoke(b);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
var dMapper = dMapConfig.CreateMapper();
|
var dMapper = dMapConfig.CreateMapper();
|
||||||
|
|
||||||
@@ -430,11 +478,15 @@ namespace xCommons.Extensions
|
|||||||
/// Convert Using Auto Mapper ...
|
/// Convert Using Auto Mapper ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
|
/// <param name="cfgAction"></param>
|
||||||
/// <typeparam name="TKey"></typeparam>
|
/// <typeparam name="TKey"></typeparam>
|
||||||
/// <typeparam name="TDest"></typeparam>
|
/// <typeparam name="TDest"></typeparam>
|
||||||
/// <typeparam name="TSource"></typeparam>
|
/// <typeparam name="TSource"></typeparam>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IDictionary<TKey, TDest> MapConvert<TKey, TDest, TSource>(this IDictionary<TKey, TSource> source)
|
public static IDictionary<TKey, TDest> MapConvert<TKey, TDest, TSource>(
|
||||||
|
this IDictionary<TKey, TSource> source,
|
||||||
|
Action<IMapperConfigurationExpression> cfgAction = null
|
||||||
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
if (source.IsNull())
|
if (source.IsNull())
|
||||||
@@ -445,8 +497,16 @@ namespace xCommons.Extensions
|
|||||||
//
|
//
|
||||||
var dMapConfig = new MapperConfiguration(b =>
|
var dMapConfig = new MapperConfiguration(b =>
|
||||||
{
|
{
|
||||||
|
//
|
||||||
b.CreateMap<TDest, TSource>()
|
b.CreateMap<TDest, TSource>()
|
||||||
.ReverseMap();
|
.ReverseMap();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Use Specified Provided Actions if Exists ...
|
||||||
|
if (!cfgAction.IsNull())
|
||||||
|
{
|
||||||
|
cfgAction.Invoke(b);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
var dMapper = dMapConfig.CreateMapper();
|
var dMapper = dMapConfig.CreateMapper();
|
||||||
|
|
||||||
|
|||||||
@@ -94,12 +94,14 @@ namespace xCommons.Extensions
|
|||||||
/// <param name="xmlFilePath"></param>
|
/// <param name="xmlFilePath"></param>
|
||||||
/// <param name="addRequiredXPoweredFilter"></param>
|
/// <param name="addRequiredXPoweredFilter"></param>
|
||||||
/// <param name="addXTokenAuthorization"></param>
|
/// <param name="addXTokenAuthorization"></param>
|
||||||
|
/// <param name="addXApiKeyAuthorization"></param>
|
||||||
/// <param name="addDefaultValueFilter"></param>
|
/// <param name="addDefaultValueFilter"></param>
|
||||||
public static void AddXSwaggerGenOptions(
|
public static void AddXSwaggerGenOptions(
|
||||||
this SwaggerGenOptions source,
|
this SwaggerGenOptions source,
|
||||||
string xmlFilePath = null,
|
string xmlFilePath = null,
|
||||||
bool addRequiredXPoweredFilter = true,
|
bool addRequiredXPoweredFilter = true,
|
||||||
bool addXTokenAuthorization = true,
|
bool addXTokenAuthorization = true,
|
||||||
|
bool addXApiKeyAuthorization = true,
|
||||||
bool addDefaultValueFilter = true
|
bool addDefaultValueFilter = true
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -210,6 +212,32 @@ namespace xCommons.Extensions
|
|||||||
});
|
});
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Handle XApiKey Authorization ...
|
||||||
|
if (addXApiKeyAuthorization)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
source.AddSecurityDefinition(nameof(XAuthorization.XApiKey), new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
In = ParameterLocation.Header,
|
||||||
|
Name = XAuthorization.XApiKey,
|
||||||
|
Type = SecuritySchemeType.ApiKey,
|
||||||
|
Description = "Api Key for Authentication ...",
|
||||||
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
source.AddSecurityRequirement(new OpenApiSecurityRequirement {
|
||||||
|
{
|
||||||
|
new OpenApiSecurityScheme {
|
||||||
|
Reference = new OpenApiReference {
|
||||||
|
Id = nameof (XAuthorization.XApiKey),
|
||||||
|
Type = ReferenceType.SecurityScheme
|
||||||
|
}
|
||||||
|
}, Array.Empty<string> ()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -221,6 +249,7 @@ namespace xCommons.Extensions
|
|||||||
/// <param name="xmlFilePath"></param>
|
/// <param name="xmlFilePath"></param>
|
||||||
/// <param name="addRequiredXPoweredFilter"></param>
|
/// <param name="addRequiredXPoweredFilter"></param>
|
||||||
/// <param name="addXTokenAuthorization"></param>
|
/// <param name="addXTokenAuthorization"></param>
|
||||||
|
/// <param name="addXApiKeyAuthorization"></param>
|
||||||
/// <param name="addDefaultValueFilter"></param>
|
/// <param name="addDefaultValueFilter"></param>
|
||||||
public static void AddXSwagger(
|
public static void AddXSwagger(
|
||||||
this IServiceCollection source,
|
this IServiceCollection source,
|
||||||
@@ -229,6 +258,7 @@ namespace xCommons.Extensions
|
|||||||
string xmlFilePath = null,
|
string xmlFilePath = null,
|
||||||
bool addRequiredXPoweredFilter = true,
|
bool addRequiredXPoweredFilter = true,
|
||||||
bool addXTokenAuthorization = true,
|
bool addXTokenAuthorization = true,
|
||||||
|
bool addXApiKeyAuthorization = true,
|
||||||
bool addDefaultValueFilter = true
|
bool addDefaultValueFilter = true
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -252,6 +282,7 @@ namespace xCommons.Extensions
|
|||||||
xmlFilePath: xmlFilePath,
|
xmlFilePath: xmlFilePath,
|
||||||
addDefaultValueFilter: addDefaultValueFilter,
|
addDefaultValueFilter: addDefaultValueFilter,
|
||||||
addXTokenAuthorization: addXTokenAuthorization,
|
addXTokenAuthorization: addXTokenAuthorization,
|
||||||
|
addXApiKeyAuthorization: addXApiKeyAuthorization,
|
||||||
addRequiredXPoweredFilter: addRequiredXPoweredFilter
|
addRequiredXPoweredFilter: addRequiredXPoweredFilter
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user