Notes
Notes - notes.io |
CurrentLoginUser currentLoginUser = (CurrentLoginUser)Utility.GetSession(AppConstants.CurrentLoginUser);
string token = "0:username:role:key";
string key = System.Configuration.ConfigurationManager.AppSettings["ServiceKey"].ToString();
if (currentLoginUser != null)
{
token = currentLoginUser.UserId + ":" + currentLoginUser.UserName + ":" + currentLoginUser.RoleName + ":" + key;
}
}
function GetHeader() {
//return { 'Authorization': 'Basic ' + btoa('@System.Configuration.ConfigurationManager.AppSettings["ServiceKey"]') }
debugger;
var token = '@token';
return { 'Authorization': 'Basic ' + btoa(token) }
}
public class AuthenticationAPI : AuthorizationFilterAttribute
{
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
{
if (actionContext.Request.Headers.Authorization == null)
{
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
}
else
{
// Gets header parameters
string authenticationString = actionContext.Request.Headers.Authorization.Parameter;
string originalString = Encoding.UTF8.GetString(Convert.FromBase64String(authenticationString));
// Gets username and password
string userId = originalString.Split(':')[0];
string userName = originalString.Split(':')[1];
string role = originalString.Split(':')[2];
string key = originalString.Split(':')[3];
// Validate username and password
if (!VaidateUser(userId, userName, key))
{
LogUnAuthorizedAccess(actionContext);
// returns unauthorized error
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
}
}
base.OnAuthorization(actionContext);
}
/// <summary>
/// User validate
/// </summary>
/// <param name="username">User Name</param>
/// <param name="password">User Password</param>
/// <returns>Return true or false</returns>
public bool VaidateUser(string userId, string userName, string key)
{
// Check if it is valid credential
if (key == "name")
{
APIHelper apiHelper = new APIHelper();
JavaScriptSerializer serializer = new JavaScriptSerializer();
var result = apiHelper.GetRequest("Account/ValidateUser", "userId=" + userId + "&userName=" + userName);
if (result != null && result == "true")
return true;
}
return false;
}
public void LogUnAuthorizedAccess(System.Web.Http.Controllers.HttpActionContext actionContext)
{
try
{
UnAuthorizedAccessModel unAuthorizedAccess = new UnAuthorizedAccessModel();
// Log UnAuthorized request
unAuthorizedAccess.UserName = actionContext.RequestContext.Principal.Identity.IsAuthenticated ? actionContext.RequestContext.Principal.Identity.Name : string.Empty;
unAuthorizedAccess.IPAddress = APIUtility.GetClientIpAddress(actionContext.Request);
unAuthorizedAccess.UnAuthorizedID = 0;
unAuthorizedAccess.AuthorizationKey = actionContext.Request.Headers.Authorization.Parameter;
unAuthorizedAccess.HostName = actionContext.Request.RequestUri.Host;
unAuthorizedAccess.Operation = actionContext.Request.Method.Method;
unAuthorizedAccess.AccessedArea = actionContext.Request.RequestUri.AbsoluteUri;
unAuthorizedAccess.AccessedDate = DateTime.Now;
APIHelper apiHelper = new APIHelper();
apiHelper.PostRequest("AuditLog/AddUnAuthorizedAccess", unAuthorizedAccess);
}
catch
{ }
}
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team