Ejemplo n.º 1
0
        public AuthenticationTokenV1 TryCreateApplicationToken(AuthenticationCredentialsV1 credentials, ApplicationIdentifierV1 applicationIdentifier)
        {
            var tokenPrefix = "app_" + applicationIdentifier.Name;
            var tokenLifetimeMilliseconds = configuration.GetApplicationTokenExpirationMilliseconds();

            return(CreateAuthenticationTokenOrNull(tokenPrefix, credentials, tokenLifetimeMilliseconds));
        }
Ejemplo n.º 2
0
        public AuthenticationTokenV1 TryCreateSessionToken(AuthenticationCredentialsV1 credentials)
        {
            var tokenPrefix = "session";
            var tokenLifetimeMilliseconds = configuration.GetSessionTokenExpirationMilliseconds();

            return(CreateAuthenticationTokenOrNull(tokenPrefix, credentials, tokenLifetimeMilliseconds));
        }
Ejemplo n.º 3
0
        private AuthenticationTokenV1 CreateAuthenticationTokenOrNull(string tokenPrefix, AuthenticationCredentialsV1 credentials, long tokenLifetimeMillis)
        {
            var validationResult = accountService.ValidateAccountCredentials(credentials.Email, credentials.HashedPassword);

            if (!validationResult.Success)
            {
                return(AuthenticationTokenV1.kInvalidToken);
            }

            var token          = authenticationTokenFactory.CreateToken(tokenPrefix);
            var expirationTime = DateTime.UtcNow.AddMilliseconds(tokenLifetimeMillis);
            var identity       = new Identity(validationResult.AccountId, validationResult.AccountName, credentials.Email, expirationTime);

            if (!identityByTokenCache.Put(token, identity))
            {
                return(AuthenticationTokenV1.kInvalidToken);
            }
            else
            {
                return(new AuthenticationTokenV1(token));
            }
        }
 public AuthenticationTokenV1 TryCreateApplicationToken(AuthenticationCredentialsV1 credentials, ApplicationIdentifierV1 applicationIdentifier)
 {
     return(authenticationService.TryCreateApplicationToken(credentials, applicationIdentifier));
 }
 public AuthenticationTokenV1 TryCreateSessionToken(AuthenticationCredentialsV1 credentials)
 {
     return(authenticationService.TryCreateSessionToken(credentials));
 }