Ejemplo n.º 1
0
        public async Task <TokenDetails> GetCurrentValidTokenAndRenewIfNecessaryAsync()
        {
            if (AuthMethod == AuthMethod.Basic)
            {
                throw new AblyException("AuthMethod is set to Auth so there is no current valid token.");
            }

            if (CurrentToken.IsValidToken())
            {
                return(CurrentToken);
            }

            if (TokenRenewable)
            {
                var token = await AuthoriseAsync();

                if (token.IsValidToken())
                {
                    CurrentToken = token;
                    return(token);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public async Task <TokenDetails> GetCurrentValidTokenAndRenewIfNecessaryAsync()
        {
            if (AuthMethod == AuthMethod.Basic)
            {
                throw new AblyException("AuthMethod is set to Auth so there is no current valid token.");
            }



            if (CurrentToken.IsValidToken(ServerTimeOffset() ?? Now()))
            {
                return(CurrentToken);
            }

            if (TokenRenewable)
            {
                var token = await AuthorizeAsync();

                var now = ServerTimeOffset() ?? Now();
                if (token.IsValidToken(now))
                {
                    CurrentToken = token;
                    return(token);
                }

                if (token != null && token.IsExpired(now))
                {
                    throw new AblyException("Token has expired: " + CurrentToken, 40142, HttpStatusCode.Unauthorized);
                }
            }

            return(null);
        }