public ActionResult <string> GetIzendaAccessToken(string message)
        {
            var userInfo = IzendaTokenAuthorization.DecryptIzendaAuthenticationMessage(message);
            var token    = IzendaTokenAuthorization.GetToken(userInfo);

            return(Ok(new { Token = token }));
        }
        public string GenerateToken()
        {
            string username   = User.Identity.Name;
            string tenantName = "";

            try
            {
                string nameIdentifierType = @"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier";
                tenantName = ((ClaimsIdentity)User.Identity).FindFirst(nameIdentifierType).Value;
                foreach (Claim cl in ((ClaimsIdentity)User.Identity).Claims)
                {
                    if (cl.Type.Contains("nameidentifier"))
                    {
                        tenantName = cl.Value;
                    }
                }
            }
            catch { }
            UserInfo user = new UserInfo {
                UserName = username, TenantUniqueName = tenantName
            };
            string token = IzendaTokenAuthorization.GetToken(user);

            return("\"" + token + "\"");  // believe it or not, otherwise our FE service takes it as errored out.
        }
Example #3
0
        private static string GetToken()
        {
            var user = new UserInfo
            {
                TenantUniqueName = ConfigurationManager.AppSettings["SystemTenant"],
                UserName         = ConfigurationManager.AppSettings["IzendaAdminUser"]
            };

            var token = IzendaTokenAuthorization.GetToken(user);

            return(token);
        }
        /// <summary>
        /// Get user/pwd and tenant info from web config file to authorize with Izenda Api
        /// In all (backend and front end) are integrated mode, authentication information will get from hosting web and send to izenda to authenticate.
        /// In standalone mode, hosting app will need to send user/pwd to izenda to authenticate.
        /// </summary>
        /// <returns></returns>
        private string GetToken()
        {
            var username         = System.Configuration.ConfigurationManager.AppSettings["izusername"];
            var tenantUniqueName = System.Configuration.ConfigurationManager.AppSettings["iztenantuniquename"];

            if (string.IsNullOrEmpty(tenantUniqueName))
            {
                tenantUniqueName = "System";
            }
            var token = IzendaTokenAuthorization.GetToken(new UserInfo {
                UserName = username, TenantUniqueName = tenantUniqueName
            });

            return(token);
        }
Example #5
0
        public ActionResult GenerateToken()
        {
            var tenantName = ((ClaimsIdentity)User.Identity).FindFirstValue("tenantName");
            var username   = ((ClaimsIdentity)User.Identity).FindFirstValue("UserName");

            var claimsIdentity = ((ClaimsIdentity)User.Identity);

            username = claimsIdentity.Claims.FirstOrDefault(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name")?.Value;
            var simpleClaims = claimsIdentity.Claims.Select(c => new{ c.Type, c.Value });

            var user = new UserInfo {
                UserName = username, TenantUniqueName = tenantName
            };
            var token = IzendaTokenAuthorization.GetToken(user);

            return(Json(new
            {
                token, username, tenantName,
                simpleClaims
            }, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// Create a custom route to intercept login requests for the Izenda API. This is needed for the
        /// Izenda Copy Console as it will only authenticate against "api/user/login".
        /// </summary>
        /// <param name="username">the username</param>
        /// <param name="password">the password</param>
        /// <returns>a json result indicating success or failure</returns>
        public ActionResult CustomAuth(string username, string password)
        {
            OperationResult authResult;
            var             serializerSettings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            var jsonResult = "";

            //validate login (more complex logic can be added here)
            #warning CAUTION!! Update this method to use your authentication scheme or remove it entirely if the copy console will not be used.
            if (username == "*****@*****.**" && password == "Izenda@123")
            {
                var user = new UserInfo {
                    UserName = username, TenantUniqueName = "System"
                };
                var token = IzendaTokenAuthorization.GetToken(user);

                var accessToken = new IzendaFramework.AccessToken
                {
                    CultureName     = "en-US",
                    Tenant          = null,
                    IsExpired       = false,
                    NotifyDuringDay = null,
                    DateFormat      = "DD/MM/YYYY",
                    Token           = token
                };

                authResult = new OperationResult {
                    Success = true, Messages = null, Data = accessToken
                };
                jsonResult = JsonConvert.SerializeObject(authResult, serializerSettings);
                return(Content(jsonResult, "application/json"));
            }

            authResult = new OperationResult {
                Success = false, Messages = null, Data = null
            };
            jsonResult = JsonConvert.SerializeObject(authResult, serializerSettings);
            return(Content(jsonResult, "application/json"));
        }
Example #7
0
        public static void RegisterLoginLogic()
        {
            //This is used for exporting only
            UserIntegrationConfig.GetAccessToken = (args) =>
            {
                return(IzendaTokenAuthorization.GetToken(new UserInfo()
                {
                    UserName = args.UserName,
                    TenantUniqueName = args.TenantId
                }));
            };

            UserIntegrationConfig.ValidateToken = (ValidateTokenArgs args) =>
            {
                var token = args.AccessToken;
                var user  = IzendaTokenAuthorization.GetUserInfo(token);

                // TenantUniqueName corresponds to the 'TenantID' field in the IzendaTenant table
                return(new ValidateTokenResult {
                    UserName = user.UserName, TenantUniqueName = user.TenantUniqueName
                });
            };
        }