You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

248 lines
7.0 KiB

using Common.Model.Config;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IdentityModel.Tokens.Jwt;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Web;
namespace JsonRx.Helper
{
/// <summary>
/// </summary>
public static class Util
{
/// <summary>
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public static string GetGuid(HttpRequestMessage request)
{
try
{
object uuidNumber = "";
request.Properties.TryGetValue("Guid", out uuidNumber);
return uuidNumber.ToString();
}
catch
{
return "";
}
}
/// <summary>
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public static string GetUsername(HttpRequestMessage request)
{
try
{
object uuidNumber = "";
request.Properties.TryGetValue("Username", out uuidNumber);
return uuidNumber.ToString();
}
catch
{
return "";
}
}
/// <summary>
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public static string GetCustomerId(HttpRequestMessage request)
{
try
{
object uuidNumber = "";
request.Properties.TryGetValue("CustomerId", out uuidNumber);
return uuidNumber.ToString();
}
catch
{
return "";
}
}
public static string GetFintechUseNo(HttpRequestMessage request)
{
try
{
object uuidNumber = "";
request.Properties.TryGetValue("FintechUseNo", out uuidNumber);
return uuidNumber.ToString();
}
catch
{
return "";
}
}
public static string GetAccessToken(HttpRequestMessage request)
{
try
{
object uuidNumber = "";
request.Properties.TryGetValue("AccessToken", out uuidNumber);
return uuidNumber.ToString();
}
catch
{
return "";
}
}
/// <summary>
/// </summary>
/// <returns></returns>
public static string GetUuid(HttpRequestMessage request)
{
// UUID number coming from http header. This header value is sending to the properties
// of Request object and capturing here.
try
{
object uuidNumber = "";
request.Properties.TryGetValue("uuid", out uuidNumber);
return uuidNumber.ToString();
}
catch
{
return "";
}
}
/// <summary>
/// </summary>
/// <returns></returns>
public static string GetScope(HttpRequestMessage request)
{
// UUID number coming from http header. This header value is sending to the properties
// of Request object and capturing here.
try
{
object uuidNumber = "";
request.Properties.TryGetValue("scope", out uuidNumber);
return uuidNumber.ToString();
}
catch
{
return "";
}
}
/// <summary>
/// </summary>
/// <returns></returns>
public static string GetClientId(HttpRequestMessage request)
{
try
{
object clientId = "";
request.Properties.TryGetValue("clientId", out clientId);
return clientId.ToString();
}
catch
{
return "";
}
}
/// <summary>
/// Since we require to choose langaue to reflect correponding kftc page and use can view
/// kftc page based on langauage selected by them. This method return provided langauge
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public static string GetKFTCLanguage(HttpRequestMessage request)
{
try
{
object clientId = "";
request.Properties.TryGetValue("language", out clientId);
return clientId.ToString();
}
catch
{
return "";
}
}
/// <summary>
/// Since we require to choose langaue to reflect correponding kftc page and use can view
/// kftc page based on langauage selected by them. This method return provided langauge
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public static string GetKFTCClientId(HttpRequestMessage request)
{
try
{
object kftcId = "";
request.Properties.TryGetValue("KftcClientId", out kftcId);
return kftcId.ToString();
}
catch
{
return "";
}
}
public static string GetClientFCMId(HttpRequestMessage request)
{
try
{
object clientFcmId = "";
request.Properties.TryGetValue("ClientFcmId", out clientFcmId);
return clientFcmId.ToString();
}
catch
{
return "";
}
}
public static string getJWTTokenClaim(string token, string claimName)
{
try
{
var tokenHandler = new JwtSecurityTokenHandler();
var securityToken = (JwtSecurityToken)tokenHandler.ReadToken(token);
var claimValue = securityToken.Claims.FirstOrDefault(c => c.Type == claimName)?.Value;
return claimValue;
}
catch (Exception)
{
//TODO: Logger.Error
return null;
}
}
public static string GetDeviceType(HttpRequestMessage request)
{
try
{
object deviceType = "";
request.Properties.TryGetValue("deviceType", out deviceType);
return deviceType != null ? deviceType.ToString() : "IOS";
}
catch
{
return "IOS";
}
}
public static string GetFullName(string fname, string mname, string lname)
{
string fullName = string.Empty;
fullName = string.Format("{0} {1}", (!string.IsNullOrEmpty(mname)) ? fname + " " + mname : fname, lname);
return fullName;
}
}
}