예제 #1
0
        /// <summary>
        /// Verify this user has a valid session
        /// </summary>
        /// <param name="session"></param>
        /// <param name="userId"></param>
        public Session Authenticate(string token)
        {
            token.Should().NotBeNullOrEmpty();

            SessionPayload requestSessionPayload = new SessionPayload();
            string         unpackagedToken       = this.UnpackageToken(token);

            if (unpackagedToken == String.Empty)
            {
                return(null);
            }
            else
            {
                requestSessionPayload.LoadJson(unpackagedToken);

                if (this._tokenValidator.IsTokenActive(requestSessionPayload.CreatedDate.ToDateTime(), this._sessionExpirationTimeInMinutes))
                {
                    SessionPayload responseSessionPayload = new SessionPayload(DateTime.UtcNow.ToCompleteDateString(), requestSessionPayload.CreatedDate.ToDateTime().AddMinutes(this._sessionExpirationTimeInMinutes).ToCompleteDateString(), requestSessionPayload.Email, requestSessionPayload.UserId.ToString(), this._siteName);
                    return(new Session(requestSessionPayload.CreatedDate.ToDateTime(), requestSessionPayload.Email, requestSessionPayload.UserId.ToInt(), token, this.PackagePayload(responseSessionPayload.ToJson())));
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #2
0
        public string GenerateSessionPayload(
            string createdDate,
            string expirationDate,
            string email,
            int userId,
            string siteName)
        {
            createdDate.Should().NotBeNullOrEmpty();
            expirationDate.Should().NotBeNullOrEmpty();
            email.Should().NotBeNullOrEmpty();
            siteName.Should().NotBeNullOrEmpty();
            userId.Should().BeGreaterThan(0);

            SessionPayload payload = new SessionPayload(createdDate, expirationDate, email, userId.ToString(), siteName);

            return(payload.ToJson());
        }