Beispiel #1
0
        internal static bool CreateToken(string apikey, TokenModelIn modelDataIn, ref TokenModelOut modelDataOut)
        {
            var unixEpoch = FromUnixTime(0);
            var expiry    = Math.Round((DateTime.UtcNow.AddMinutes(modelDataIn.SessionMinutes) - unixEpoch).TotalSeconds);
            var issuedAt  = Math.Round((DateTime.UtcNow - unixEpoch).TotalSeconds);
            var notBefore = Math.Round((DateTime.UtcNow.AddMonths(6) - unixEpoch).TotalSeconds);

            var payload = new Dictionary <string, object>
            {
                { "version", constVersionToken },
                { "userid", modelDataIn.UserId },
                { "surname", modelDataIn.UserFullName },
                { "role", "User" },
                { "nbf", notBefore },
                { "iat", issuedAt },
                { "exp", expiry },
                //{"sub:userid", ModelDataIn.UserId},
                //{"sub:username", ModelDataIn.UserName},
                //{"sub:fullname", ModelDataIn.UserFullName},
            };

            byte[] apikeyObj = GetBytesSecretKey(apikey);
            var    token     = JWT.Encode(payload, apikeyObj, JwsAlgorithm.HS256);

            modelDataOut.Token = token;
            return(true);
        }
Beispiel #2
0
        public static TokenModelOut CreateToken(string clientApiKey, TokenModelIn ModelData)
        {
            var tokenReturn = new TokenModelOut()
            {
                //IdUsuario = ModelData.IdUsuario,
                //Usuario = ModelData.Usuario,
                //NombreUsuario = ModelData.NombreUsuario,
                //Token = clientToken,
            };

            CreateToken(clientApiKey, ModelData, ref tokenReturn);

            return(tokenReturn);
        }